我在播放來自Internet的視頻時在標題中提到了此錯誤。使用此錯誤消息檢查網絡後,應用程序崩潰:AVPlayerItem無法與AVPlayer的多個實例關聯
- (void)viewDidLoad
{
NSString *urlAdress = [NSString stringWithFormat:@"http://www.dailymotion.com/video/x108t8t"];
//NSString *urlAdress = [[NSBundle mainBundle] pathForResource:@"video8" ofType:@"mp4"];in this case video plays.
NSURL *videoURL = [NSURL fileURLWithPath:urlAdress];
self.mpvc = [[MPMoviePlayerViewController alloc] initWithContentURL:videoURL];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlaybackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
self.mpvc.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
//when using file in resources use MPMovieSourceTypeFile,when online then streaming
[self presentMoviePlayerViewControllerAnimated:mpvc];
[super viewDidLoad];
}
//and here is moviePlaybackDidFinish method
- (void)moviePlayBackDidFinish:(NSNotification *)notification
{
MPMoviePlayerController *theMovie = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:theMovie];
[theMovie stop];
[theMovie.view removeFromSuperview];
NSLog(@" playback finish Called......");
}
這是整個代碼。我已經通過大部分教程,stackoverflow的問題,但不能得到一個單一的解決方案
您是否在同一屏幕上使用MPMoviePlayerViewController的多個實例? –
在您的問題中發佈此方法。這裏很難閱讀。 –
什麼是avplayeritem我dint在我的代碼中使用了這個? – iAhmed