0

When i tried a video saved on the Xcode project , it worked. then when i changed it with a url , it always returns this error :

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

}

Here's my code :

 NSURL *url = [NSURL fileURLWithPath:@"https://m.youtube.com/watch?v=9MNAeGWd_04"];

movieController = [[MoviePlayerVC alloc]initWithContentURL:url];
movieController.view.frame = self.view.bounds;
[movieController.moviePlayer setShouldAutoplay:YES];

[movieController.moviePlayer setControlStyle:MPMovieControlStyleFullscreen];
[[movieController view] setTransform:CGAffineTransformMakeRotation(M_PI / 2)];
[self presentViewController:movieController animated:NO completion:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(playbackStateDidChange:)
                                             name:@"MPAVControllerPlaybackStateChangedNotification"
                                           object:nil];
Iman
  • 1,037
  • 2
  • 11
  • 19

4 Answers4

1

fileURLWithPath: expects a local path url - /User/blah/blah.mp3

Try to use [NSURL URLWithString:@"https://m.youtube.com/watch?v=9MNAeGWd_04"]

Nimrod Gutman
  • 967
  • 1
  • 8
  • 21
  • actually quellish is correct, you can't play youtube videos in MPMoviePlayer... check http://stackoverflow.com/questions/1779511/play-youtube-videos-with-mpmovieplayercontroller-instead-of-uiwebview for reference – Nimrod Gutman Jun 11 '14 at 09:05
1

IF YOU PLAY FROM URL THEN TRY THIS

-(void)playFromLiveUrl
{

        NSURL *aUrl = [NSURL URLWithString:@"*YOUR URL*"];
        _moviePlayer =  [[MPMoviePlayerController alloc]initWithContentURL:aUrl];
        _moviePlayer.controlStyle = MPMovieControlStyleNone;
        _moviePlayer.shouldAutoplay = YES;
        _moviePlayer.view.frame = asyvideoImage.frame;
        _moviePlayer.scalingMode=MPMovieScalingModeFill;
        [self.view addsubview _moviePlayer.view];
        [_moviePlayer prepareToPlay];
        [_moviePlayer setFullscreen:NO animated:NO];

}

IF YOU ARE USE LOCAL FILE THEN USE THIS

-(void)playFromLocal
{

        _moviePlayer =  [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:@"** LOCAL PATH ** "]];
        _moviePlayer.controlStyle = MPMovieControlStyleNone;
        _moviePlayer.shouldAutoplay = YES;
        _moviePlayer.view.frame = asyvideoImage.frame;
        _moviePlayer.scalingMode=MPMovieScalingModeFill;
        [self.view addsubview _moviePlayer.view];
        [_moviePlayer prepareToPlay];
        [_moviePlayer setFullscreen:NO animated:NO];

}
Mitul Bhadeshiya
  • 1,208
  • 1
  • 12
  • 28
  • it open black screen only. – Iman Jun 10 '14 at 13:13
  • yes i added this URL "https://m.youtube.com/watch?v=9MNAeGWd_04"and i changed the "asyvideoImage.frame" to CGRectmake(0,0,320,548) – Iman Jun 10 '14 at 13:15
  • if you want to play video from the youtube URL then you have to find some custom class to play video from youtube URL – Mitul Bhadeshiya Jun 10 '14 at 13:17
  • Actually its a url from sever , but i replaced it with youtube as i found that no urls are working with the code :( – Iman Jun 10 '14 at 13:19
  • please check the below link you can get something from that 1)http://stackoverflow.com/questions/1779511/play-youtube-videos-with-mpmovieplayercontroller-instead-of-uiwebview 2) http://stackoverflow.com/questions/6911171/mpmovieplayercontroller-is-playing-youtube-video – Mitul Bhadeshiya Jun 10 '14 at 13:21
1

The MPMoviewPlayerController Can't get your format. U r try to load the MPMoviePlayerController with youTube link, it won't work (as u can see :)

Here u can find the iPhone video format support.

Try to load your MoviePlayer something like this (for example .m3u8 format):

[movieController setContentURL:[NSURL URLWithString:@"http://devimages.apple.com/iphone/samples/bipbop/gear1/prog_index.m3u8"]];
Community
  • 1
  • 1
gran33
  • 10,218
  • 7
  • 40
  • 67
0

MPMoviePlayerController cannot play a Flash Youtube URL. Use a web view instead. UIWebView on iOS is smart enough play youtube content.

You can see the video formats MPMoviePlayer and AVFoundation support here

quellish
  • 20,584
  • 4
  • 72
  • 81