【问题标题】:Show controls in Movie Player when the movie is finished电影播放完毕后在电影播放器​​中显示控件
【发布时间】:2012-10-31 07:26:25
【问题描述】:

我想在电影结束时显示电影播放器​​控件,所以我将观察者添加到 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];
            }
        }
    }
}

到目前为止,一切都运行良好并且控件出现了,但是当我点击屏幕以隐藏它们时,控件消失并很快再次出现(类似于闪光灯),然后我需要再次点击查看隐藏控件..

有人知道我为什么会遇到这个问题吗?或者有另一个想法在视频完成时显示控件?

【问题讨论】:

    标签: iphone ios video mpmovieplayercontroller movieplayer


    【解决方案1】:

    首先调试打印MPMoviePlayerView的子视图,记下子视图,找到控制视图的名称。

    这是我在应用程序中进行的调试。

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

    然后我检查了控件视图的名称并将其从播放器中删除。将其设置为隐藏。

    - (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];
                    }
                }
            }
        }
    }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多