8

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]

eldermao
  • 633
  • 8
  • 18

1 Answers1

5

Just small piece of code:

NSString *path = [[NSBundle mainBundle] pathForResource:@"splash" ofType:@"mp4"];
NSURL *videoURL = [NSURL fileURLWithPath:path];
AVPlayer* player = [AVPlayer playerWithURL:videoURL];
WINSergey
  • 1,977
  • 27
  • 39
  • 1
    my video is on the local server and I want to play it on my device. – Raksha Saini Aug 24 '17 at 08:34
  • @Rex just change NSURL *videoURL = [NSURL URLWithString:@"http://cdn3.viblast.com/streams/dash/vod-bunny/XXX.mp4"]; – WINSergey Aug 24 '17 at 08:46
  • Yes I am using this one also. but that not play my video in device – Raksha Saini Aug 24 '17 at 09:40
  • @Rex can you give me a link to gist with your code? – WINSergey Aug 24 '17 at 11:54
  • 1
    i am using [this](https://stackoverflow.com/a/45854740/3607051). It works perfectly in Simulator. but when I run this on real device it shows [error](https://stackoverflow.com/q/45854668/3607051). please help – Raksha Saini Aug 24 '17 at 12:03
  • @Rex can you upload part of the project to github for example? I want help you but I really don't get what is the problem with AVPlayer – WINSergey Aug 24 '17 at 22:06
  • @WINSergery My problem looks like that [problem](https://stackoverflow.com/questions/45854668/local-video-play-on-real-device-iphone) – Raksha Saini Aug 26 '17 at 06:07