MPMoviePlayerController"正在加载电影..."

Acc*_*yyc 5 iphone video objective-c mpmovieplayercontroller iphone-video

我正在尝试使用iOS 4.1在iPhone上的资源文件夹中播放视频文件.MPMoviePlayerViewController显示视图,但它只会在活动指示器旋转时显示"正在加载电影...".谁知道这个的原因?我尝试过各种适用于iPhone的视频格式,每次都有相同的结果.

电影播放器​​响应显示和隐藏控件等操作.

我的代码:

-(void) playVideoNamed:(NSString *)videoName
{
    // I get the path like this so the user can enter extension in the filename
    NSString *path = [NSString stringWithFormat:@"%@/%@", 
                      [[NSBundle mainBundle] resourcePath], videoName];
    NSLog(@"Path of video file: %@", path);

    RootViewController *rootController = [(DerpAppDelegate *)[[UIApplication sharedApplication] delegate] viewController];

    NSURL *url = [NSURL URLWithString:path];

    MPMoviePlayerViewController *vc = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
    vc.moviePlayer.movieSourceType = MPMovieSourceTypeFile;

    [rootController presentMoviePlayerViewControllerAnimated:vc];
    [vc.moviePlayer prepareToPlay]; // Not sure about this... I've copied this code from various others that claims this works
    [vc.moviePlayer play];
} 
Run Code Online (Sandbox Code Playgroud)

Acc*_*yyc 20

发现问题:

NSURL *url = [NSURL URLWithString:path];
Run Code Online (Sandbox Code Playgroud)

必须替换为:

NSURL *url = [NSURL fileURLWithPath:path];
Run Code Online (Sandbox Code Playgroud)

很难发现那一个......