Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AVPlayer not playing local videos

I've been struggling with this for some hours... I'm trying to play a video I download and save using AVPlayer but nothing shows up. What surprised me the most is that if I use Apple's sample url for testing http live streaming that video does play. (http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8) However, when I change the url to the local file path the video doesn't play. I recorded the video with the iPhone and verified that the format (.mov) is playable. 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);

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

EDIT: Solved by using [NSURL fileURLWithPath:local_url_string]

like image 235
eldermao Avatar asked Jul 04 '13 21:07

eldermao


People also ask

What is Avplayerlayer?

An object that presents the visual contents of a player object.

How do I use AVPlayer in SwiftUI?

VideoPlayer in SwiftUIimport AVKit import SwiftUI struct ContentView: View { var body: some View { VideoPlayer(player: AVPlayer(url: Bundle. main. url(forResource: "movie", withExtension: "mp4")!)) } }


1 Answers

Just small piece of code:

NSString *path = [[NSBundle mainBundle] pathForResource:@"splash" ofType:@"mp4"];
NSURL *videoURL = [NSURL fileURLWithPath:path];
AVPlayer* player = [AVPlayer playerWithURL:videoURL];
like image 176
WINSergey Avatar answered Oct 19 '22 12:10

WINSergey