I have an application that downloads movies from an ftp-server and then plays them with an MPMoviePlayerController. However the movieplayer fails with MPMovieFinishReasonPlaybackError.
the code looks like this:
NSURL *url = [NSURL fileURLWithPath:[contents objectAtIndex:index]];
NSLog(@"url: %@",url);
self.movieController = [[MPMoviePlayerController alloc] initWithContentURL:url];
the nslog gives this answer:
url: file://localhost/var/mobile/Applications/E8C9DFE8-9802-4EC1-B560-3EEE96E0AF5E/Documents/media/testfilm.mov
Does anybody have an idea on how to get the movie to play? If I add the movie to the project and use the following code the movie works.
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"testfilm" ofType:@"mov"]];
You are using fileURLWithPath:
for a remote file, that is wrong.
Use URLWithString:
for remote files instead.
See the reference on that exact subject - particularly the parameters section;
URLWithString:
Creates and returns an NSURL object initialized with a provided string.
+ (id)URLWithString:(NSString *)URLString
Parameters
URLString
The string with which to initialize the NSURL object. Must be a URL that conforms to RFC 2396. This method parses URLString according to RFCs 1738 and 1808. (To create NSURL objects for file system paths, use fileURLWithPath:isDirectory:
instead.)
Return Value
An NSURL object initialized with URLString. If the string was malformed, returns nil.
Discussion
This method expects URLString to contain any necessary percent escape codes, which are ‘:’, ‘/’, ‘%’, ‘#’, ‘;’, and ‘@’. Note that ‘%’ escapes are translated via UTF-8.