Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Playing a Downloaded Video from the Documents Directory with Cocoa-Touch

I'm trying to get my app to play a video file that's been downloaded to the documents directory. I know the file is getting downloaded, but I can't seem to get the file to play, here is my code:

-(IBAction)play{

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"%@/piggy.m4v"];

NSURL *movieURL = [NSURL fileURLWithPath:path];


_player = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
[self.view addSubview:_player.view];

_player.controlStyle = MPMovieControlStyleDefault;
_player.shouldAutoplay = YES;


[_player setFullscreen:YES animated:YES];


[_player play];

}
like image 908
Kevin Fey Avatar asked Jul 18 '12 19:07

Kevin Fey


1 Answers

This looks like some kind of bug, but you have to set your path like that:

 NSString *vidPath = [[NSBundle mainBundle] pathForResource:@"promo" ofType:@"mp4"];
 NSURL *url = [NSURL fileURLWithPath:vidPath isDirectory:NO]; //THIS IS THE KEY TO GET THIS RUN :) 
 [introPlayer setContentURL:url];
like image 75
Marcin Małysz Avatar answered Oct 13 '22 15:10

Marcin Małysz