【问题标题】:Playing Saved Videos in Documents Dictionary With AVPlayer使用 AVPlayer 播放文档字典中保存的视频
【发布时间】:2017-06-13 19:13:57
【问题描述】:

我已经在我的文档文件夹中保存了一个 1mb 的大钱兔子,我尝试用我的 AVPlayer 加载和播放它,为此我使用了这个代码

 NSString* documentsPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
             NSString* foofile = [documentsPath stringByAppendingPathComponent:string]; // string is file name

        NSURL *url = [NSURL URLWithString:foofile];
         NSLog(@" exsits %@ :",foofile);


        AVPlayer*player1 = [AVPlayer playerWithURL:url];
        AVPlayerViewController *Controller = [[AVPlayerViewController alloc] init];
        Controller.player = player1;
        [player1 play];
        [self presentViewController:Controller animated:YES completion:nil];

但我得到的不是播放器

simulator screenshot

编辑 文件 URL 看起来像这样

/Users/usrname/Library/Developer/CoreSimulator/Devices/4453818A-0617-479B-B98C-3FC544A24D00/data/Containers/Data/Application/D7449628-0A67-4294-9471-98F5596FE596/Documents/tt1823672.mp4

【问题讨论】:

  • 您正在从string 而不是foofile 创建您的网址
  • NSURL *url = [NSURL URLWithString:foofile];
  • @dan,对不起,我更正了,但还是一样

标签: ios objective-c avplayer nsfilemanager


【解决方案1】:

格式化评论让我很生气,所以我只是发布作为答案。

我记得,如果你想播放一些本地文件,url的前缀通常是file://...

但是如果你直接创建url,前缀可能是http://..

所以您可能想更改您的代码
[NSURL URLWithString:foofile]

[NSURL fileURLWithPath:foofile];

所以.. url 的前缀应该是file://..,并且应该是本地文件的目标。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多