Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Notification when movie player control gets visible/hidden?

I just want to know if its possible to get a notification when the playback control gets visible or hidden?

For example, I want to present a video with the style:

self.moviePlayerController.controlStyle = MPMovieControlStyleEmbedded;

When the video starts playing, the playback controls gets visible and automatically disappears. If the user just tab on the video, the controls appear.

I need a notification so i can adjust my view (reposition some additional buttons under the MPMoviePlayerController view. Is that possible? Because unfortunately I found nothing in the documentation.

like image 865
geforce Avatar asked Jul 19 '12 12:07

geforce


1 Answers

I am afraid that there are no documented notifications for those events.

You may be lucky and find something by sniffing all posted notifications as in the following answers:

Trapping and tracing all notifications

How to receive NSNotifications from UIWebView embedded YouTube video playback


There is however a way to simply link your controls with those of MPMoviePlayerControler's. That way is definitely undocumented and it does carry a strong risk of getting rejected when trying to sell your app on iTunes.

First, you need to locate the interface view within MPMoviePlayerController, which up until today is represented by a class called MPInlineVideoOverlay when using the embedded interface. Once again, please note that his this carries a big chance or breaking as Apple may decide any day to use a different naming.

/**
 * This quirky hack tried to locate the interface view within the supposingly opaque MPMoviePlayerController
 * view hierachy.
 * @note This has a fat chance of breaking and/or getting rejected by Apple
 *
 * @return interface view reference or nil if none was found
 */
- (UIView *)interfaceViewWithPlayer:(MPMoviePlayerController *)player
{
    for (UIView *views in [player.view subviews])
    {
        for (UIView *subViews in [views subviews])
        {
            for (UIView *controlView in [subViews subviews])
            {
                if ([controlView isKindOfClass:NSClassFromString(@"MPInlineVideoOverlay")])
                {
                    return controlView;
                }
            }
        }
    }
    return nil;
}

If the returns a proper view, you just add your own additions to the interface on to of it using UIView addSubview: Once you did that, your controls will be part of the player's interface, shown and hidden right together with it (also adhering to all animations etc.).

like image 177
Till Avatar answered Oct 04 '22 15:10

Till