Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MPMoviePlayer overlay in fullscreen mode (iPad)

I want to add a button on my video player when it is playing in fullscreen. I created an Overlay on my videoplayer and it's working very well on an iPhone. I tryed to same thing on a iPad, but the button never appear.

Here's my code :

 NSArray *windows = [[UIApplication sharedApplication] windows];
 if ([windows count] > 1){
       UIWindow * moviePlayerWindow = [windows objectAtIndex:1];
       NSArray * subviews = [moviePlayerWindow subviews];
       UIView * videoView = [subviews objectAtIndex:0];
       [videoView addSubview:myButton];
}

It seams like the ipad dosen't create a UIWindow for the fullscreen mode.

Anyone have any idea on how I could do this?

Thanks!

like image 200
iamdewthedew Avatar asked Oct 28 '10 18:10

iamdewthedew


2 Answers

I found a solution to this problem a few weeks ago:

It seems this method does not work on the iPad (I havent checked iPhone SDK 4>) so in order to get round it you can do the following.

After adding your video and setting to fullscreen you can add your controls directly to the UIWindow (e.g. [[[[UIApplication sharedApplication] windows] objectAtIndex:0] addSubView:myView]), they will then appear on top of your video video.

The only problem I have found with this is that they dont obey the orientation rules of the view and I have manually had to program the rotation code in the willRotateToInterfaceOrientation method of the view.

like image 134
Anthony Main Avatar answered Nov 18 '22 19:11

Anthony Main


The solution from @tigermain works.

[[[[UIApplication sharedApplication] windows] objectAtIndex:0] addSubView:myView]

But the views added to the window do not follow the orientation.

Solution for the orientation is to use NSNotificationCenter, UIApplicationDidChangeStatusBarOrientationNotification.

    // assign a notification
    id center = [NSNotificationCenter defaultCenter];
    [center addObserver:self
             selector:@selector(didRotate:)
                 name:UIApplicationDidChangeStatusBarOrientationNotification
               object:nil];

    // this method will get called when the orientation changes
    -(void) didRotate:(NSNotification*)notification {

        UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
        NSLog(@"%d", orientation);
        // ... transform view accordingly to the enum 'UIInterfaceOrientationXXX'
    }
like image 39
Porsche Avatar answered Nov 18 '22 20:11

Porsche