Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MPMoviePlayerController "Loading Movie..."

I'm trying to play a video file from the resource folder on iPhone with iOS 4.1. The MPMoviePlayerViewController displays the view but it only says "Loading Movie..." forever with the activity indicator rotating. Anyone knows the cause of this? I've tried with various video formats that are supposed to work on iPhone, same result every time.

The movie player responds to actions like showing and hiding the controls.

My code:

-(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];
} 
like image 756
Accatyyc Avatar asked May 20 '11 11:05

Accatyyc


1 Answers

Found out the issue:

NSURL *url = [NSURL URLWithString:path];

Must be replaced with:

NSURL *url = [NSURL fileURLWithPath:path];

Hard to spot that one...

like image 195
Accatyyc Avatar answered Oct 20 '22 10:10

Accatyyc