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

后端 未结 8 1582
长发绾君心
长发绾君心 2020-12-05 13:58

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 exte

8条回答
  •  遥遥无期
    2020-12-05 14:11

    If you have problems to get the ContentType of your connection you could cycle through the playable MIME types and create symbolic links to the actual file with the extension and check if they are playable. Like so:

    NSLog(@"linked path: %@",[videoURL absoluteString]);
    NSString* linkedPath;
    AVURLAsset* asset;
    NSFileManager *filemgr = [NSFileManager defaultManager];
    
    for (NSString* string in [AVURLAsset audiovisualMIMETypes]) {
    
        if ([string containsString:@"video/"]) {
    
            NSLog(@"Trying: %@",string);
    
            linkedPath = [[videoURL absoluteString] stringByAppendingPathExtension:[string stringByReplacingOccurrencesOfString:@"video/" withString:@""]];
            NSLog(@"linked path: %@",linkedPath);
    
            if (![filemgr fileExistsAtPath:linkedPath]) {
                NSError *error = nil;
                [filemgr createSymbolicLinkAtURL:[NSURL URLWithString:linkedPath] withDestinationURL:videoURL error:&error];
                if (error) {
                   NSLog(@"error %@",error.localizedDescription);
                }
            }
    
           asset = [AVURLAsset assetWithURL:[NSURL URLWithString:linkedPath]];
            if ([asset isPlayable]) {
                NSLog(@"Playable");
                break;
            }else{
                NSLog(@"Not Playable");
                asset = nil;
            }
        }
    
    }
    

提交回复
热议问题