-(IBAction)play:(id)sender
{
thumbImageView.alpha=0.0;
NSString *stringvideo=[NSString stringWithFormat:@"http://streaming-service",[[NSUserDefaults standardUserDefaults]valueForKey:@"VideoIdselected"]];
NSString *videoURLString = stringvideo;
NSURL *url = nil;
url = [NSURL URLWithString:videoURLString];
self.moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:url];
if (self.moviePlayerController)
{
/* Save the movie object. */
[self setMoviePlayerController:self.moviePlayerController];
[self installMovieNotificationObservers];
/* Specify the URL that points to the movie file. */
[self.moviePlayerController setContentURL:url];
[self.moviePlayerController setMovieSourceType:MPMovieSourceTypeStreaming]; // for streaming
self.moviePlayerController.controlStyle = MPMovieControlStyleEmbedded;
// [self.videoPlayer setMovieSourceType:MPMovieSourceTypeStreaming];
// self.moviePlayerController.shouldAutoplay = YES;
[self.moviePlayerController.view setFrame: CGRectMake(0, 0, 320,160)];
[self.moviePlayerController setFullscreen:NO animated:YES];
[self.moviePlayerController view].backgroundColor = [UIColor lightGrayColor];
[self.view addSubview:self.moviePlayerController.view];
[self.view bringSubviewToFront:self.moviePlayerController.view];
[self.moviePlayerController prepareToPlay];
//self.moviePlayerController.useApplicationAudioSession = NO;
[self.moviePlayerController play];
}
}
嗨,我正在尝试在我的 iphone 应用上播放视频。该代码播放本地文件,但在用于从服务器流式传输视频时出现错误“由于未捕获的异常‘NSInvalidArgumentException’导致应用程序终止,原因:‘一个 AVPlayerItem 不能与多个 AVPlayer 实例关联’”而崩溃。此外,该链接在浏览器中流式传输视频绝对正常,但我无法在应用程序中播放视频。请帮忙 。谢谢