AVPlayer does not play local videos

I struggled with this for several hours ... I try to play the video that I download and save using AVPlayer but nothing appears. What surprised me most was that if I use a sample Apple sample to test the live HTTP broadcast, the video is playing. ( http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8 ) However, when I change the URL to the local path to the file, the video does not play. I recorded a video from the iPhone and confirmed that the format (.mov) is playing. Here is the code block:

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); 

Output Example: Playing video at: /var/mobile/Applications/B298EE7D-D95D-4CCC-8466-2C0270E2071E/Documents/394665262.174180.mov

EDIT: Solved using [NSURL fileURLWithPath: local_url_string]

+4
source share
1 answer

Just a small piece of code:

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

Source: https://habr.com/ru/post/1489798/


All Articles