我一直在爲此而努力了一段時間... 我試圖播放視頻我下載並保存使用AVPlayer,但沒有顯示出來。 什麼最讓我吃驚的是,如果我使用蘋果的示例網址測試HTTP實時流 該視頻確實起到。 (http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8) 然而,當我更改URL到本地文件路徑的視頻不能播放。我用iPhone錄製了視頻並驗證了格式(.mov)是可播放的。下面是代碼塊:AVPlayer不播放本地視頻
AVPlayer *mPlayer = [[AVPlayer alloc] init];
//mPlayer = [mPlayer initWithURL:[NSURL URLWithString:@"http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"]];
mPlayer = [mPlayer initWithURL:filePath];
playerLayer = [AVPlayerLayer playerLayerWithPlayer:mPlayer];
[[[self view] layer] insertSublayer:playerLayer atIndex:3];
[playerLayer setFrame:self.view.bounds];
[mPlayer play];
NSLog(@"Playing video at: %@", filePath);
示例輸出: Playing video at: /var/mobile/Applications/B298EE7D-D95D-4CCC-8466-2C0270E2071E/Documents/394665262.174180.mov
編輯: 通過使用解決[NSURL fileURLWithPath:local_url_string]
如何創建'filePath'? –
謝謝Martin!我通過使用'fileURLWithPath'解決了這個問題 – mauzepeda
你不應該發送多個'init' /'init ...'消息給同一個對象。您應該只在第一行創建AVPlayer,例如'[[AVPlayer alloc] initWithURL:[NSURL fileURLWithPath:...]]''。 –