iOS 8 MPMoviePlayerPlaybackDidFinishNotification无法正常工作

时间:2014-09-22 19:43:00

标签: ios8 mpmovieplayercontroller

我使用Xcode 6和iOS 8 SDK。

如果视频无法播放,则启动MPMoviePlayer时。 MPMoviePlayerPlaybackDidFinishNotification无效。

我参考这篇文章: [How to get an error description when playback fails on MPMoviePlayerController 但iOS8不起作用。

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(MPFinished: ) name:MPMoviePlayerPlaybackDidFinishNotification object:self.MoviePlayer];

如何做才能解决这个问题?感谢。

2 个答案:

答案 0 :(得分:2)

我有同样的问题,我找到的唯一解决方案是用AVPlayerViewController替换MPMoviePlayerController(自AVKit框架中的iOS 8开始提供)。

答案 1 :(得分:1)

确保“object”参数属于MPMoviePlayerController类,而不是MPMoviePlayerViewController。

如果self.MoviePlayer是MPMoviePlayerViewController,只需更改此内容:

[[NSNotificationCenter defaultCenter] addObserver:self
     selector:@selector(MPFinished:)
     name:MPMoviePlayerPlaybackDidFinishNotification
     object:self.MoviePlayer];

到此:

[[NSNotificationCenter defaultCenter] addObserver:self
     selector:@selector(MPFinished:) 
     name:MPMoviePlayerPlaybackDidFinishNotification
     object:self.MoviePlayer.moviePlayer];

发送通知的对象是 self.MoviePlayer.movi​​ePlayer