Play downloaded video from document directory using Cocoa -Touch

I am trying to get my application to play a video file uploaded to a document directory. I know the file is loading, but I can’t 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];

}
+5
source share
2 answers

This seems like some kind of error, but you should indicate your path as follows:

 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];
+11
source

The problem will be with this line: NSString *path = [documentsDirectory stringByAppendingPathComponent:@"%@/piggy.m4v"];

Change it to NSString *path = [documentsDirectory stringByAppendingPathComponent:@"piggy.m4v"];

0
source

All Articles