4

I have an iPad app that has a movie preview view in the top half of the screen and thumbnails in the bottom half of the screen. When the user taps a thumbnail that movie starts playing in the movie preview view using a MPMoviePlayerViewController with control style MPMovieControlStyleEmbedded. The embedded style has the built in functionality of allowing the user to tap a fullscreen button to show the movie in fullscreen.

All of the above functionality works great but I want to always show a watermark over movies in the preview and fullscreen views. The watermark shows correctly in the preview view when I add a label to vcMoviePlayer.view but I cannot get that label to show over the movie in fullscreen mode after the fullscreen button has been pressed. I'm adding the label to vcMoviePlayer.view (making sure to bring the label to the front) when the movie player sends the MPMoviePlayerDidEnterFullscreenNotification but it still does not appear. Has anyone else seen this behavior? Does anyone know how to get a view to appear over a movie playing in fullscreen after the fullscreen button has been tapped? I've burned a lot of time trying to figure this out and any help is very very appreciated. Thanks!

Wes
  • 103
  • 1
  • 5

2 Answers2

4

I use this code and works on iOS 5 and iOS 6

UIWindow *window = [[UIApplication sharedApplication].windows objectAtIndex:0];
UIView * videoView = [[window subviews] lastObject];

UIView *customView = [[UIView alloc] initWithFrame:CGRectMake(0.0f,0.0f,100.0f,100.0f)];
[videoView addSubview:customView];

On iOS 5 you have to remove the customView on MPMoviePlayerWillExitFullscreenNotification

jcesarmobile
  • 51,328
  • 11
  • 132
  • 176
3

When in fullscreen mode, MPMoviePlayerController does not use the supplied superview anymore but directly displays itself on the current (key) window.

For finding something you can put your view/s on once the player is in fullscreen mode, do as follows:

UIWindow *window = [UIApplication sharedApplication].keyWindow;
if (!window)
{
    window = [[UIApplication sharedApplication].windows objectAtIndex:0];
}

Now you can put your custom views on top of that window and it will be visible while MPMoviePlayerController is being in fullscreen mode.

UIView *customView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 
                                                              0.0f, 
                                                              100.0f, 
                                                              100.0f)];
[window addSubview:customView];

For finding the right moment to add/remove your custom views, register the following notifications and do it within the registered handlers:

MPMoviePlayerDidEnterFullscreenNotification and MPMoviePlayerWillExitFullscreenNotification

Till
  • 27,559
  • 13
  • 88
  • 122
  • 1
    this: UIWindow *window = [UIApplication sharedApplication].keyWindow; if (!window) { window = [[UIApplication sharedApplication].windows objectAtIndex:0]; } doesn't work for me, but UIWindow *window = [[UIApplication sharedApplication].windows objectAtIndex:0]; works – jcesarmobile Mar 25 '13 at 13:49