ios MPMoviePlayerController can't play local files on simulator
I'm new here. I'm already 2 days browsing for solutions, but unhappy.
Here is my code:
NSString *docPath = [NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; NSString *docaPathFull = [docPath stringByAppendingPathComponent:@"/IMG_0003.m4v"]; self.videoURL = [NSURL fileURLWithPath:docaPathFull]; MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:videoURL]; UIImage *thumbnail = [player thumbnailImageAtTime:4.0 timeOption:MPMovieTimeOptionExact]; player = nil; self.imageView.image = thumbnail;
Problem is, i can't make video file visible for MPMoviePlayerController. I can't get thumbnail and I can't play it, just black player and loading infinity.
I did try:
NSString*thePath=[[NSBundle mainBundle] pathForResource:@"IMG_0003" ofType:@"m4v"]; self.videoURLtheurl=[NSURL fileURLWithPath:thePath];
self.videoURL = [[NSBundle mainBundle] URLForResource:@"IMG_0005" withExtension:@"mov"];
NSString *filePath = @"/Users/[user]/Documents/video/IMG_0004.mov"; self.videoURL = [NSURL fileURLWithPath:filePath];
If you have any ideas how to save my life, please do!!!
Many thanks for you time.
Actually this is my working example from my project. Make sure you added your m4v file to your project. The notification was a need for me, maybe it is not necessary for you.
theMovie = [[MPMoviePlayerController alloc] initWithContentURL: [NSURL fileURLWithPath: [[NSBundle mainBundle] pathForResource:@"yourmovie" ofType:@"m4v"]]]; theMovie.view.frame = CGRectMake(0, 0, 320, 480); [theMovie setControlStyle:MPMovieControlStyleNone]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:theMovie]; [self.view addSubview:theMovie.view]; [theMovie play];