我想从网上下载视频并将该文件写入本地文件夹。我为此做了以下代码:
if(videoUrl!=Nil)
{
if(moviePlayer==NULL)
{
NSString *newPath = @"/Users/theuser/Desktop/data/b.m3u8";
NSData *videoData = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"]];
NSLog(@"data=%@",videoData);
[videoData writeToFile:newPath atomically:YES];
}
}
我正在同一应用程序中检索视频。我有以下代码:
- (void)viewDidLoad
{
[super viewDidLoad];
// NSString *directory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *newPath = @"/Users/theuser/Desktop/data/b.m3u8";//[directory stringByAppendingPathComponent:@"myMovie.m3u8"];
NSLog(@"path=%@",newPath);
moviePlayerController=[[MPMoviePlayerController alloc]initWithContentURL:[NSURL fileURLWithPath:newPath isDirectory:NO]];
moviePlayerController.scalingMode=MPMovieScalingModeAspectFill;
moviePlayerController.view.frame=CGRectMake(320,200,320,200);
[self.view addSubview:moviePlayerController.view];
[moviePlayerController play];
NSLog(@"played");
}
但我得到以下异常:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'An AVPlayerItem cannot be associated with more than one instance of AVPlayer'
为什么会这样?