[英]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.