我在播放来自互联网的视频时收到了标题中提到的错误。
- (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问题但无法获得单一解决方案
答案 0 :(得分:0)
您所引用的案例未正确创建您的网址。
您正在尝试播放远程流,因此URL必须是远程流。
使用fileURLWithPath
创建本地文件网址。远程URL使用URLWithString
创建。
本地文件网址
NSURL *videoURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"video8" ofType:@"mp4"]];
远程网址
NSURL *videoURL = [NSURL URLWithString:@"http://www.dailymotion.com/video/x108t8t"];
答案 1 :(得分:0)