开发者社区 问答 正文

如何从文件目录中播放视频

应用中存储视频的名字是'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。

展开
收起
爵霸 2016-03-17 11:53:55 2289 分享 版权
1 条回答
写回答
取消 提交回答
  • NSString *content = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:NULL];
    这个是从文件中读取出字符串。。 video2.mov 是保存在沙盒中的话,filepath已经是路径了,如果是应用中,要用 [nsbundle mainbundle] pathForResource:@"video2" ofType:@"mov]

    2019-07-17 19:05:03
    赞同 展开评论
问答分类:
问答地址: