OStack程序员社区-中国程序员成长平台

标题: ios - 在 iphone 中单击完成按钮时,MP 电影 Controller 会删除 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 16:37
标题: ios - 在 iphone 中单击完成按钮时,MP 电影 Controller 会删除

我在 MPmovieController 中播放视频它工作正常,但播放完整视频时播放器会移除。我希望当用户按下完成按钮时视频应该停止在这里是我正在使用的代码。

     NSURL*myURL=[NSURL fileURLWithPath:url];
     MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:myURL];

     [[NSNotificationCenter defaultCenter] addObserver:self
     selectorselector(moviePlaybackComplete
     name:MPMoviePlayerPlaybackDidFinishNotification
     object:moviePlayerController];

     [moviePlayerController.view setFrame:CGRectMake(0,0,320,480)];
     [self.view addSubview:moviePlayerController.view];
     [moviePlayerController play];

- (void)moviePlaybackCompleteNSNotification *)notification
     {
    MPMoviePlayerController *moviePlayerController = [notification object];
    [[NSNotificationCenter defaultCenter] removeObserver:self                           name:MPMoviePlayerPlaybackDidFinishNotification                             object:moviePlayerController];
    [moviePlayerController.view removeFromSuperview];
    [moviePlayerController release];
       }



Best Answer-推荐答案


试试这个:

    NSURL *fileURL=[NSURL URLWithString:[[array objectAtIndex:videoid] valueForKey"VideoUrl"]];
    self.mpPlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:fileURL];
    [self presentMoviePlayerViewControllerAnimated:self.mpPlayer];
    [self.mpPlayer.moviePlayer prepareToPlay];
    self.mpPlayer.moviePlayer.shouldAutoplay=NO;
    [self.mpPlayer.moviePlayer play];



 - (void)moviePlayBackDidFinishNSNotification*)notification
   {
      MPMoviePlayerController *moviePlayer = [notification object];
      [[NSNotificationCenter defaultCenter] removeObserver:self
                                                name:MPMoviePlayerPlaybackDidFinishNotification
                                              object:moviePlayer];
      [moviePlayer pause];
      [self dismissMoviePlayerViewControllerAnimated];
      // [moviePlayer.view removeFromSuperview];
  }

也许会有所帮助。

愉快的编码...

关于ios - 在 iphone 中单击完成按钮时,MP 电影 Controller 会删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20088584/






欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) Powered by Discuz! X3.4