Notification when movie player control gets visible/hidden?
Asked Answered
C

1

6

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.

Corrade answered 19/7, 2012 at 12:19 Comment(0)
H
5

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.).

Haploid answered 19/7, 2012 at 17:4 Comment(1)
Sidenote explaining that mentioned rejection risk: I had used this exact hack in a major app release and it got through undetected....Haploid

© 2022 - 2024 — McMap. All rights reserved.