繁体   English   中英

使用AVPlayer播放文档字典中的已保存视频

[英]Playing Saved Videos in Documents Dictionary With AVPlayer

我已经在文档文件夹中保存了一个大小为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];

但是我不是玩家而是我

模拟器屏幕截图

EDIT文件的URL看起来像这样

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

格式化注释使我丧命,所以我只是发布答案。

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

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

因此,您可能需要更改代码
[NSURL URLWithString:foofile]

[NSURL fileURLWithPath:foofile];

因此.. url的前缀应为file://.. ,并且应以本地文件为目标。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM