Heim > Fragen und Antworten > Hauptteil
如题,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的创建方式,试试不要临时创建