【问题标题】:MPMoviePlayerController plays after canceling in 3.1.2MPMoviePlayerController 在 3.1.2 中取消后播放
【发布时间】:2016-12-31 20:32:00
【问题描述】:

我在 3.1.2 中遇到了 MPMoviePlayerController 的问题。

如果我取消播放器它仍在加载,播放器将关闭。但是,视频稍后会在后台开始播放。阻止它的唯一方法是播放另一个视频或关闭应用程序。这似乎在 3.2+ 中运行良好。

这就是我正在做的事情:

- (void)loadMoviePlayer
{
    // Register to receive a notification when the movie has finished playing. 
    [[NSNotificationCenter defaultCenter] addObserver:self 
                                             selector:@selector(moviePlayBackDidFinish:) 
                                                 name:MPMoviePlayerPlaybackDidFinishNotification 
                                               object:nil];

    if ([NSClassFromString(@"MPMoviePlayerController") instancesRespondToSelector:@selector(view)])
    {

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 30200
        // running iOS 3.2 or better
        MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:@"http://www.mysite.com/myvideo.m3u8"]];
        [moviePlayer.view setBackgroundColor:[UIColor blackColor]];
        [moviePlayer.moviePlayer setControlStyle:MPMovieControlStyleFullscreen];
        //      [moviePlayer.moviePlayer setControlStyle:MPMovieControlStyleNone];
        [self presentMoviePlayerViewControllerAnimated:moviePlayer];
        [moviePlayer.moviePlayer prepareToPlay];    
        [moviePlayer.moviePlayer play]; 
#endif
    }
    else 
    {
        MPMoviePlayerController *mMPPlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:@"http://www.mysite.com/myvideo.m3u8"]];
        mMPPlayer.scalingMode=MPMovieScalingModeFill;
        mMPPlayer.backgroundColor=[UIColor blackColor];
        [mMPPlayer play];
    } 

}

- (void) moviePlayBackDidFinish:(NSNotification*)notification 
{    
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque];
    [[UIApplication sharedApplication] setStatusBarHidden:NO];

    // Remove observer
    [[NSNotificationCenter  defaultCenter] 
     removeObserver:self
     name:MPMoviePlayerPlaybackDidFinishNotification 
     object:nil];

    [self dismissModalViewControllerAnimated:YES];
}

我今天早上添加了moviePlayBackDidFinish。当我点击取消时它会被调用,但dismissModalViewControllerAnimated 似乎没有做任何事情。我也试过 removeFromSuperView,但我的播放器没有响应。

那么,如何确保玩家在点击“取消”后不玩呢?

提前致谢。

【问题讨论】:

    标签: iphone mpmovieplayercontroller


    【解决方案1】:

    您可能在 MPMoviePlayerController 中遇到过一个老错误。过去,我们实际上必须在播放适当的内容后播放几乎空的(黑色,静音)M4V,以确保播放器在某些阶段停止时不会尝试在后台继续播放。该错误表现为可听声音,但没有中止/停止视频的图片。

    然而,停止时还有一些值得尝试的事情(假设您的 MPMoviePlayerController 实例称为moviePlayer);

    • 将当前播放位置设置为完整的影片时长moviePlayer.currentPlaybackTime = moviePlayer.duration;
    • 在您的通知处理程序[moviePlayer stop]; 中发送另一个停止

    【讨论】:

    • 由于某种原因,停止不起作用。我不得不使用 [moviePlayer release]。我有另一个电影播放器​​,它使用流媒体。在第二次取消并启动播放器后,对该播放器使用释放会导致播放器崩溃。按照您的建议,我使用 stop 解决了这个问题。
    【解决方案2】:

    就我而言,我发现设置以下行最终会阻止电影播放器​​播放:

    moviePlayer.contentURL = nil;
    

    (将moviePlayer 用作MPMoviePlayerController 的实例)。

    【讨论】:

      猜你喜欢
      • 2014-04-02
      • 1970-01-01
      • 1970-01-01
      • 2013-03-10
      • 1970-01-01
      • 1970-01-01
      • 2010-11-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多