AVPlayer cannot play local video file
習慣沉默
習慣沉默 2017-05-02 09:25:44
0
3
930

As mentioned, AVPlayer refuses to play local video files (videos are absolutely fine), but network loading links can be played. Could you please tell me what’s going on?

The code is as follows:

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];
習慣沉默
習慣沉默

reply all(3)
世界只因有你

Hello, have you solved it? My problem is exactly the same as yours, the network can work but the local video cannot be played.

为情所困

The URL of your local video is wrong. How is it possible to get the address on Mac in iOS?

过去多啦不再A梦

Local URL needs to start with: file:///, such as file:///var/mobile/Containers/Data/Application/6272EE22-EF19-48E5-85BA-4A986B22AC39/Documents/Movie4.mov.
But I see that yours already starts with file, so you can pay attention to how the AVPlayer is created and try not to create it temporarily

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template