【问题标题】:MPMoviePlayerController can't read file in document pathMPMoviePlayerController 无法读取文档路径中的文件
【发布时间】:2012-07-02 16:52:57
【问题描述】:

我录了一段视频,复制到路径

NSURL *videoPath =[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUsersDomainMask,YES) objectAtIndex:0],@"/output.mov"]]; 

然后使用 MPMoviePlayer 播放:

MPMoviePlayerController *player = [[MPMovieController alloc] initWithContentURL:videoPath];

这不起作用。视频无法加载。文件路径是

"/var/mobile/Applications/12341235-12354125-123412-41/Documents/output.mov"

有人知道为什么吗?

【问题讨论】:

    标签: iphone ios mpmovieplayercontroller document


    【解决方案1】:

    出于某种奇怪的原因,MPMoviePlayerController 似乎不喜欢某些 NSURLs,即使它们被视为有效对象。

    “秘密”是获取文件路径为NSString,然后使用[NSURL fileURLWithPath:URLStringPath] 创建用于创建MPMoviePlayerController 实例的URL。

    【讨论】:

    • 谢谢。这行得通。但是,我仍然无法使用 requestThumbnailImagesAtTimes:timeOption: 来获取缩略图。它说:domain avfoundationerrordomain code=-11800。你知道为什么吗?
    • 你帮我省了几个小时的头痛。
    【解决方案2】:

    我想你忘记为你的文件路径设置 / 像这样使用

    NSURL *videoPath =[NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/%@",[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUsersDomainMask,YES) objectAtIndex:0],@"output.mov"]];
    

    【讨论】:

    • 非常感谢。我只是发现我应该使用 [NSURL fileURLWithPath:videoPath] 而不是单独使用 videoPath。但是,我仍然无法使用该播放器获得缩略图。它说“该操作无法竞争。”你知道为什么吗?
    • 而不是nsurl urlwithstring 使用nsurl fileurlwithpath 作为你的文件路径获取操作进程
    猜你喜欢
    • 2015-11-17
    • 1970-01-01
    • 2018-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-01
    • 2015-09-27
    • 1970-01-01
    相关资源
    最近更新 更多