Search code examples
iosobjective-cmpmovieplayercontrollerdropbox

MPMoviePlayerViewController with dropbox URL error: _itemFailedToPlayToEnd:


I get the above error with the following code:

    NSURL *url = [NSURL fileURLWithPath:@"https://www.dropbox.com/s/crzu6yrwt35tgej/flexao.mp4?dl=1" isDirectory:NO];

    self.player = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
    self.player.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
    [self presentMoviePlayerViewControllerAnimated:self.player];

When I copy the file to my bundle and load the url from there it works.

I guess it has something to do with my dropbox link, but I also don't know how to generate a different link or filename.


Solution

  • Modify your code as below

    //You're using the URL https://www.dropbox.com/s/crzu6yrwt35tgej/flexao.mp4, but that's not a link to a video... it's a link to a page with a video on it.

    To convert it to a direct link to the video, change www.dropbox.com to dl.dropboxuser.com, like this: https://dl.dropboxusercontent.com/s/crzu6yrwt35tgej/flexao.mp4

    NSURL *url = [NSURL URLWithString:@"https://dl.dropboxusercontent.com/s/crzu6yrwt35tgej/flexao.mp4"];
    
    self.player = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
    self.player.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
    [self presentMoviePlayerViewControllerAnimated:self.player];
    

    Hope it fixes the issue..!