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!
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.
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'
    }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With