應用中存儲視頻的名字是'video2.MOV',現在要播放出了問題。
因為無法從文件中獲取。
-(void)playVideo:(NSTimer *)theTimer
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"video2.MOV"];
NSLog(@"filePath - %@",filePath);
NSString *content = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:NULL];
NSLog(@"contentPath - %@",content);
MPMoviePlayerViewController *videoPlayerView = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:content]];
[ [CCDirector sharedDirector] presentMoviePlayerViewControllerAnimated:videoPlayerView];
[videoPlayerView.moviePlayer play];
}
在控制台中,每次獲取contentPath 都是null。
NSString *content = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:NULL];
這個是從文件中讀取出字符串。。 video2.mov 是保存在沙盒中的話,filepath已經是路徑了,如果是應用中,要用 [nsbundle mainbundle] pathForResource:@"video2" ofType:@"mov]