Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MPMoviePlayerController doesn't play from Documents folder

Desperated. Hello everybody! I am having some issues with MPMoviePlayerController. I've made it working with videos from NSBundle. But that's not what I need. I need to play it from Documents directory, because that is the place I store the recorded videos, wich URLs are stored in CoreData. but lets leave this aside, and simplify the code to its minimum needed. This code actually WORKS if using the contentURL, wich leads to NSBundle. After it, what I do to get to the docs place. What I do:

    NSURL *contentURL = [[NSBundle mainBundle] URLForResource:@"Oct_08_2012_10_00_51" withExtension:@"mp4"]; // this works
NSString* docPath = [NSSearchPathForDirectoriesInDomains
                     (NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString * docaPathFull = [NSString stringWithFormat:@"%@%@", docPath, @"/Oct_08_2012_10_00_51.mp4"];
NSURL * docUrl= [NSURL URLWithString: docaPathFull];
BOOL ex = [[NSFileManager defaultManager] fileExistsAtPath:docaPathFull];
NSLog(@"file exists: %d, path using docPath: %@",ex, docaPathFull);
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:docUrl];
player.shouldAutoplay = YES;
player.controlStyle = MPMovieControlStyleEmbedded;
[player.view setFrame: self.thumbButton.bounds];
[player prepareToPlay];
[self.view addSubview: player.view];
[player play];

What we have:

2012-10-08 13:14:43.532 Voto[11968:907] file exists: 1, path using docPath: /var/mobile/Applications/07B8574A-A3BA-4B23-BB3F-995B33A01B95/Documents/Oct_08_2012_10_00_51.mp4
2012-10-08 13:14:43.907 Voto[11968:907] content URL: file://localhost/var/mobile/Applications/07B8574A-A3BA-4B23-BB3F-995B33A01B95/Voto.app/Oct_08_2012_10_00_51.mp4
2012-10-08 13:14:44.265 Voto[11968:907] doc URL: /var/mobile/Applications/07B8574A-A3BA-4B23-BB3F-995B33A01B95/Documents/Oct_08_2012_10_00_51.mp4
2012-10-08 13:14:45.343 Voto[11968:907] [MPAVController] Autoplay: Disabling autoplay for pause
2012-10-08 13:14:45.344 Voto[11968:907] [MPAVController] Autoplay: Disabling autoplay
2012-10-08 13:14:46.518 Voto[11968:907] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 1, on player: 0)
2012-10-08 13:14:46.540 Voto[11968:907] [MPAVController] Autoplay: Enabling autoplay
2012-10-08 13:14:46.554 Voto[11968:907] [MPAVController] Autoplay: Likely to keep up or full buffer: 0
2012-10-08 13:14:46.555 Voto[11968:907] [MPAVController] Autoplay: Skipping autoplay, not enough buffered to keep up.
2012-10-08 13:14:46.557 Voto[11968:907] [MPAVController] Autoplay: Enabling autoplay
2012-10-08 13:14:46.567 Voto[11968:907] [MPCloudAssetDownloadController] Prioritization requested for media item ID: 0
2012-10-08 13:14:46.871 Voto[11968:907] [MPAVController] Autoplay: Enabling autoplay

So, the file exists... Questions i've looked through:

MPMoviePlayer load and play movie saved in app documents

MPMoviePlayerController does not work with movie in documents folder

MPMoviePlayerViewController play movie from Documents directory - objective-c

I also checked ut with class reference, nothing specific about playing from Documents. My projects settings: using latest iOS 6, Deployment target 5.0 Testing on both iOS6 iPhone simulator and an iPad with iOS 6. If i forgot to add something, please remind me, I will do it immediately.

Please, help! :)

like image 850
Dumoko Avatar asked Nov 27 '22 09:11

Dumoko


1 Answers

Well you'r not building the file URL the correct way, you should do it like this:

NSString *docPath = [NSSearchPathForDirectoriesInDomains
                     (NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *docaPathFull = [docPath stringByAppendingPathComponent:@"/Oct_08_2012_10_00_51.mp4"];
NSURL *docUrl= [NSURL fileURLWithPath:docaPathFull];

You should add directories and file to a path with the stringByAppendingPathComponent method of NSString; Also when creating the file URL use fileURLWithPath: on NSURL, this willl create a correct NSURL for the giving path.

like image 157
rckoenes Avatar answered Dec 25 '22 21:12

rckoenes