How to play movie files with no file extension on iOS with MPMoviePlayerController or AVPlayer?

Michael picture Michael · Mar 31, 2011 · Viewed 9.8k times · Source

I want to play a movie in iOS 4.3 on the iPad. I've successfully used MPMoviePlayerController and AVPlayer to load files from a remote URL when the filename has a file extension. However, when I use a CDN that doesn't return the filename (just an un-guessable random name), neither MPMoviePlayerController or AVPlayer seem to be able to cope.

Is there a way to tell either player that it really is a movie of type x and it should just get on playing it?

MPMoviePlayerController will return the following error from it's changed state notification:

{
    MPMoviePlayerPlaybackDidFinishReasonUserInfoKey = 1;
    error = "Error Domain=MediaPlayerErrorDomain Code=-12847 \"This movie format is not supported.\" UserInfo=0x5b60030 {NSLocalizedDescription=This movie format is not supported.}";
}

I know that file is a valid m4v file, as when I rename it all is fine.

Answer

Andrii Tishchenko picture Andrii Tishchenko · May 8, 2013

File at tmp

NSString* _filePath

Create symlink

NSFileManager *filemgr = [NSFileManager defaultManager];
NSString *slink = [_filePath stringByAppendingPathExtension:@"m4v"];
if (![filemgr fileExistsAtPath:slink]) {
    NSError *error = nil;
    [filemgr createSymbolicLinkAtPath:[_filePath stringByAppendingPathExtension:@"m4v"] withDestinationPath: _filePath error: &error];
    if (error) {
        ...
    }
}
...

play video by slink