user1495599
user1495599

Reputation: 13

MPMoviePlayerController can't read file in document path

I recorded a video and copied it to the path

NSURL *videoPath =[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUsersDomainMask,YES) objectAtIndex:0],@"/output.mov"]]; 

Then use MPMoviePlayer to play it:

MPMoviePlayerController *player = [[MPMovieController alloc] initWithContentURL:videoPath];

This does not work. The video can't get loaded. The file path is

"/var/mobile/Applications/12341235-12354125-123412-41/Documents/output.mov"

Does anyone know why?

Upvotes: 1

Views: 797

Answers (2)

Senthilkumar
Senthilkumar

Reputation: 2481

i think you forgot to set / for your file path use like this

NSURL *videoPath =[NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/%@",[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUsersDomainMask,YES) objectAtIndex:0],@"output.mov"]];

Upvotes: 0

Rog
Rog

Reputation: 18670

For some weird reason, MPMoviePlayerController doesn't seem to like certain NSURLs even though they are deemed as valid objects.

The "secret" is to get the file path as NSString and then use [NSURL fileURLWithPath:URLStringPath] to create the URLs your are using to create the MPMoviePlayerController instance.

Upvotes: 8

Related Questions