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];
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?
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