问题描述
- 怎么从文件目录中播放视频
-
应用中存储视频的名字是'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]
时间: 2024-10-29 15:42:07