我有这个函数将NSData写入文档字典 -
- (void)writeData
{
NSString *str = @"http://labs.widespace.com/resources/banner/ikea/verkligheten/video.m4v";
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:str];
NSLog(@"%@",path);
NSLog(@"About to Write Data");
NSData* data0 = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:str]];
[data0 writeToFile:path atomically:YES];
NSLog(@"Writting Data Completed");
}
后来我读了这个数据并尝试使用MPMoviePlayerController播放视频,但不幸的是这个 不玩 -
- (void)readData
{
NSString *str = @"http://labs.widespace.com/resources/banner/ikea/verkligheten/video.m4v";
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:str];
NSURL* url = [[NSURL alloc] initFileURLWithPath:path];
NSLog(@"url:%@",url);
NSError *error = nil;
BOOL isReacahble = [url checkResourceIsReachableAndReturnError:&error];
NSLog(@"isReachable :%i,%@",isReacahble,error);
BOOL fileExist = [[NSFileManager defaultManager] fileExistsAtPath:path];
if(fileExist)
{
NSLog(@"File Exist in path");
}
else
{
NSLog(@"NO File Exist");
}
MPMoviePlayerController *moviePlayer=[[MPMoviePlayerController alloc] initWithContentURL:url];
[moviePlayer prepareToPlay];
NSLog(@"movie player:%@",moviePlayer);
[moviePlayer setControlStyle: MPMovieControlStyleFullscreen];
[moviePlayer.view setFrame:CGRectMake(0, 0,320, 480)];
[self.view addSubview:moviePlayer.view];
moviePlayer.shouldAutoplay = YES;
[moviePlayer play];
}
当我尝试播放时,会显示以下错误 -
2013-01-17 11:21:07.067 VideoCheck[338:907] [MPAVController] Autoplay: Disabling autoplay for pause
2013-01-17 11:21:07.068 VideoCheck[338:907] [MPAVController] Autoplay: Disabling autoplay
2013-01-17 11:21:07.090 VideoCheck[338:907] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 1, on player: 0)
2013-01-17 11:21:07.091 VideoCheck[338:907] movie player:<MPMoviePlayerController: 0x21078250>
2013-01-17 11:21:07.093 VideoCheck[338:907] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 1, on player: 0)
2013-01-17 11:21:07.102 VideoCheck[338:907] [MPAVController] Autoplay: Enabling autoplay
2013-01-17 11:21:07.113 VideoCheck[338:907] [MPAVController] Autoplay: Likely to keep up or full buffer: 0
2013-01-17 11:21:07.114 VideoCheck[338:907] [MPAVController] Autoplay: Skipping autoplay, not enough buffered to keep up.
2013-01-17 11:21:07.115 VideoCheck[338:907] [MPAVController] Autoplay: Enabling autoplay
2013-01-17 11:21:07.121 VideoCheck[338:907] [MPCloudAssetDownloadController] Prioritization requested for media item ID: 0
2013-01-17 11:21:07.149 VideoCheck[338:907] [MPAVController] Autoplay: Enabling autoplay
有人可以运行代码并提供一些有关此处发生的事情的信息吗?请有人帮助我。我正在使用iOS 6。
答案 0 :(得分:0)
在wrieData
方法中,不要将URL
名称作为文件,而只提供video
的名称。像
NSString *path = [documentsDirectory stringByAppendingPathComponent:[str lastPathComponent]];
并在readData
方法中也这样做。