簡體   English   中英

AVPlayer不播放本地視頻

[英]AVPlayer not playing local videos

我一直在努力解決這個問題......我正在嘗試播放我下載並使用AVPlayer保存的視頻,但沒有顯示任何內容。 讓我感到驚訝的是,如果我使用Apple的示例網址來測試視頻確實播放的http直播。 http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8 )但是,當我將網址更改為本地文件路徑時,視頻無法播放。 我用iPhone錄制了視頻並驗證了格式(.mov)是否可播放。 這是代碼塊:

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]解決

只是一小段代碼:

NSString *path = [[NSBundle mainBundle] pathForResource:@"splash" ofType:@"mp4"];
NSURL *videoURL = [NSURL fileURLWithPath:path];
AVPlayer* player = [AVPlayer playerWithURL:videoURL];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM