无法播放视频

时间:2012-06-26 13:28:29

标签: iphone objective-c ios

我想从网上下载视频并将该文件写入本地文件夹。我为此做了以下代码:

     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'

为什么会这样?

0 个答案:

没有答案