[英]Playing Saved Videos in Documents Dictionary With AVPlayer
i have saved a 1mb big buck bunny onto my documents folder, and i tried to load and play it with my AVPlayer,for this i used this code 我已经在文档文件夹中保存了一个大小为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];
but instead of the player i am getting this 但是我不是玩家而是我
EDIT File URL looks something like this 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
/Users/usrname/Library/Developer/CoreSimulator/Devices/4453818A-0617-479B-B98C-3FC544A24D00/data/Containers/Data/Application/D7449628-0A67-4294-9471-98F5596FE596/Documents/tt1823672.mp4
Formatting comment was killing me, so I just post as answer. 格式化注释使我丧命,所以我只是发布答案。
As I remembered, if you want to play some local files, the prefix of the url usually is file://...
. 我记得,如果要播放一些本地文件,则URL的前缀通常是
file://...
But if you create url directly, prefix might will be http://..
. 但是,如果直接创建url,则前缀可能是
http://..
So you might want to change your code 因此,您可能需要更改代码
[NSURL URLWithString:foofile]
to 至
[NSURL fileURLWithPath:foofile];
so.. url should had a prefix of file://..
, and should be target to local files. 因此.. url的前缀应为
file://..
,并且应以本地文件为目标。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.