如題,AVPlayer這貨整死不播放本地視頻文件(視頻絕對沒問題),而網絡加載鏈接是可以播放的,煩勞各位大大看看咋回事?
程式碼如下:
NSURL *url = [NSURL fileURLWithPath:@"/Users/tangkunyin/Desktop/mp4ForDownloadTest.mp4"];
AVAsset *movieAsset = [AVURLAsset assetWithURL:url];
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithAsset:movieAsset];
AVPlayer *player = [AVPlayer playerWithPlayerItem:playerItem];
AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:player];
playerLayer.frame = CGRectMake(0, 0, KDeviceWidth, 300);
playerLayer.videoGravity=AVLayerVideoGravityResize;
[self.view.layer addSublayer:playerLayer];
[player play];
过去多啦不再A梦2017-05-02 09:27:44
本地URL需要:file:///開頭,例如file:///var/mobile/Containers/Data/Application/6272EE22-EF19-48E5-85BA-4A986B22AC39/Documents/Movie4.mov。
但我看到你的已經是file開頭的了,所以你可以注意下AVPlayer的創作方式,試試看不要暫時建立