【问题标题】:MPMoviePlayerController ends immediatelyMPMoviePlayerController 立即结束
【发布时间】:2012-09-11 13:07:54
【问题描述】:

我正在尝试从我的资源文件中加载一个 25 秒的 mp4 电影,但是当我播放它时,我的 MPMoviePlayerPlaybackDidFinishNotification 选择器会立即使用 MPMovieFinishReasonPlaybackEnded 调用。当我记录我的播放状态时,它会显示:

MPMoviePlaybackStatePlaying
MPMoviePlaybackStatePaused
MPMoviePlaybackStateStopped
MovieFinishReasonPlaybackEnded
MPMoviePlaybackStatePlaying
MPMoviePlaybackStatePaused

尽管我只调用了一次 play 方法。我希望有人可以帮助我。

-- 编辑显示我的代码:

MPMoviePlayerController* player = [[[MPMoviePlayerController alloc] initWithContentURL:movieURL] autorelease];

if (player)
{

    self.moviePlayerController = player;

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(moviePlayBackDidFinish:)
                                                 name:MPMoviePlayerPlaybackDidFinishNotification
                                               object:player];

  [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(moviePlayerPlaybackStateDidChange:)
                                                 name:MPMoviePlayerPlaybackStateDidChangeNotification
                                               object:player];


    player.contentURL = movieURL;

    player.movieSourceType = MPMovieSourceTypeFile;

    player.controlStyle = MPMovieControlStyleNone;

    player.fullscreen = YES;

    switch (orientation) {
        case UIInterfaceOrientationLandscapeLeft:
            player.view.transform = CGAffineTransformMakeRotation(90.0f * (M_PI / 180.0f));
            break;
        case UIInterfaceOrientationLandscapeRight:
            player.view.transform = CGAffineTransformMakeRotation(-90.0f * (M_PI / 180.0f));
            break;
        default:
            break;
    }

    player.view.frame = self.view.bounds;

    [self.view addSubview:player.view];
}

[self.moviePlayerController play]

【问题讨论】:

    标签: iphone ios media-player mpmovieplayercontroller


    【解决方案1】:

    self.moviePlayerController 是保留属性吗?如果没有,MPMoviePlayerController 实例将很快被释放(由autorelease),您可能会得到类似的行为。

    【讨论】:

      【解决方案2】:

      如果没有更多代码可供查看,我建议尝试播放您知道可以播放的另一个文件。例如,从这个示例项目中抓取电影:http://developer.apple.com/library/ios/#samplecode/MoviePlayer_iPhone/Introduction/Intro.html 并查看它是否可以播放。

      当我尝试播放格式不正确的文件时,我也遇到过类似的情况。


      嗯...我看不出有什么问题。你确定movieURL是正确的吗?你是怎么得到的?

      为了记录,这就是我展示电影的方式,尽管它的效果与你正在做的不太一样。

      NSString *path = [[NSBundle mainBundle] pathForResource:movieFileName ofType:@"m4v"];
      
      // If path is NULL (the resource does not exist) return to avoid crash
      if (path == NULL)
          return;
      
      NSURL *url = [NSURL fileURLWithPath:path];
      MPMoviePlayerViewController *mpViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
      mpViewController.moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
      mpViewController.moviePlayer.shouldAutoplay = YES;
      
      // NOTE: This can sometimes crash the app in the Simulator. This is a known bug
      // in xcode: http://stackoverflow.com/a/8317546/472344
      [self presentMoviePlayerViewControllerAnimated:mpViewController];
      [mpViewController release];
      

      【讨论】:

      • 那么您可能必须展示您的代码才能让任何人帮助您。
      猜你喜欢
      • 2014-10-02
      • 2020-04-16
      • 1970-01-01
      • 2020-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-23
      • 2010-09-05
      相关资源
      最近更新 更多