MPMoviePlayerController error _itemFailedToPlayToEnd while playing youtube video iOS 7

11,703

Solution 1

Yes after so much researching i found to the following soluction.

MPMoviePlayerController directly will not play the youtube videos. you have to extract the video URL and set video URL to MPMoviePlayerController. after this video will be played.

There are lots of API available that gives the extracted video URL.

Some of them are below

XCDYouTubeKit

HCYoutubeParser

But using this API your application might be rejected. you should have to use on your risk.

Best way to play youtube videos is the WebView.

Solution 2

Ok!!! the problem is that the player doesn't know what you are trying to play,

  1. you can try to change the name to x.mp4
  2. you can debug the project and see that the path and the file you are trying to play exists.
Share:
11,703
Sunny Shah
Author by

Sunny Shah

I am intensely passionate about, and skilled in, engineering Mac OS X, iOS and Tizen applications. I have efficiency to execute the ideas in an efficient way. Now it has been above 4+ years experience. Experience developing and designing an enterprise application. Comprehensive knowledge of software development (Computer programming, documenting , Testing, deployment,Bug fixing, etc.) Skype ID: Sunny.shah.d Email: [email protected]

Updated on June 05, 2022

Comments

  • Sunny Shah
    Sunny Shah almost 2 years

    I've seen this mentioned a few places around the web but have yet to find answer anywhere.

    I am using ALMovieplayercontroller library. Everything works fine but when i am trying to play Youtube video it gives me error.

    _itemFailedToPlayToEnd: { kind = 1; new = 2; old = 0; }

    EDIT

    - (void)setContentURL:(NSURL *)contentURL {
    
        self.movieSourceType = MPMovieSourceTypeStreaming;
        [super setContentURL:contentURL];
        [[NSNotificationCenter defaultCenter] postNotificationName:ALMoviePlayerContentURLDidChangeNotification object:nil];
        [self play];
    }
    

    Here is my code

    ALMoviePlayerControls *movieControls = [[ALMoviePlayerControls alloc] initWithMoviePlayer:self.moviePlayer style:ALMoviePlayerControlsStyleDefault];
    //[movieControls setAdjustsFullscreenImage:NO];
    [movieControls setBarColor:[UIColor colorWithRed:195/255.0 green:29/255.0 blue:29/255.0 alpha:0.5]];
    [movieControls setTimeRemainingDecrements:YES];
    
    //assign controls
    [self.moviePlayer setControls:movieControls];
    [self.view addSubview:self.moviePlayer.view];
    self.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
    
    //THEN set contentURL
    [self.moviePlayer setContentURL:[NSURL URLWithString:@"http://www.youtube.com/watch?v=NaosmAGx8NM"]];
    

    I am not able to find the solution for this.

    Please Help.

    • Gralex
      Gralex over 10 years
      Do you solve this trouble?
    • Sunny Shah
      Sunny Shah over 10 years
      @Sk0prion i have answered my question
    • Marco
      Marco over 10 years
      @Sunnyshah please accept your own answer to close this question.
    • Sunny Shah
      Sunny Shah about 8 years
  • Lirik
    Lirik over 10 years
    Can u give an example url you trying to set?
  • Sunny Shah
    Sunny Shah over 10 years
    Please check the updated question the URL that i am using is from youtube
  • Lirik
    Lirik over 10 years
    Ok, i see you are trying to load a regular youtube url. unfortunately, that will not work on ios. You can see alternatives here: stackoverflow.com/questions/1779511/…. hope that helps :)
  • Sunny Shah
    Sunny Shah about 10 years
    We are not talking to play local video. Here we wants to play the YouTube Videos.
  • ElizaS
    ElizaS about 10 years
    I understand... sorry I had the same error so maybe my answer will help to somebody.