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];
} 

Answers


Found out the issue:

NSURL *url = [NSURL URLWithString:path];

Must be replaced with:

NSURL *url = [NSURL fileURLWithPath:path];

Hard to spot that one...


Need Your Help

Remove all whitespaces in a file- Linux

regex linux bash sed

How would I remove ALL whitespaces in a given file in Linux?

Require confirmation before opening fancybox

javascript jquery javascript-events fancybox

I need the user to confirm that he wants to end the current before opening the fancybox to create a new game.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.