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]
filePath
created? – Martin RfileURLWithPath
– eldermaoinit
/init…
messages to the same object. You should create the AVPlayer only in that first line, as[[AVPlayer alloc] initWithURL:[NSURL fileURLWithPath:…]]
. – Peter Hosey