3

I want to show movie player controls when the movie is finished, so I add observer to NSNotificationCenter :

- (void)movieFinishedCallback:(NSNotification*)aNotification
{
    // Obtain the reason why the movie playback finished
    NSNumber *finishReason = [[aNotification userInfo] objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey];

    if ([finishReason intValue] == 0)
    {
        [self showControls];
    }

   // Handle other reasons 
}


- (void)showControls
{
    for(id views in [[[self.playerVC moviePlayer] view] subviews]){
        for(id subViews in [views subviews]){
            for (id controlView in [subViews subviews]){
                [controlView setAlpha:1.0];
                [controlView setHidden:NO];
            }
        }
    }
}

till now every thing is working well and the controls were appeared, but when I tap on the screen in order to hide them, the controls disappeared and appeared again quickly (something like flash), then I need to tap again on the view to hide the controls ..

anybody knows why I got this issue ? or has another idea to show the controls when the video is finished ?

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Muhannad Dasoqie
  • 313
  • 3
  • 17

1 Answers1

0

First debug and print the subviews of the MPMoviePlayerView and write down the subviews and find the name of the control view.

This is the debugging i got in my app.

Printing description of subViews:
<MPVideoContainerView: 0x7f936950f6e0; frame = (0 0; 375 667); autoresize = W+H; layer = <CALayer: 0x7f936950fa30>>
Printing description of controlView:
<MPVideoPlaybackOverlayView: 0x7f9369659a70; frame = (0 0; 375 667); alpha = 0; hidden = YES; autoresize = W+H; tag = 1004; layer = <CALayer: 0x7f93696c4710>>
Printing description of subViews:
<MPVideoContainerView: 0x7f936950f6e0; frame = (0 0; 375 667); autoresize = W+H; layer = <CALayer: 0x7f936950fa30>>
Printing description of views:
<MPSwipableView: 0x7f9369510290; frame = (0 0; 375 667); autoresize = W+H; gestureRecognizers = <NSArray: 0x7f9369510d30>; layer = <CALayer: 0x7f9369510620>>

Then i just checked the name of the control view and removed it form the player. Set it to hidden.

- (void)hideControls
{
    for(id views in [[player view] subviews]){
        for(id subViews in [views subviews]){
            for (id controlView in [subViews subviews]){
                if ( [controlView isKindOfClass:NSClassFromString(@"MPVideoPlaybackOverlayView")] ) {
                    [controlView setAlpha:0.0];
                    [controlView setHidden:YES];
                }
            }
        }
    }
}
Arpit Dhamane
  • 503
  • 7
  • 19