1

I am trying to play a mp4 video on my web site.

MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:@"http://mywebsite.com/video.mp4"]];
    moviePlayer.view.frame = CGRectMake(0, 0, 500, 500);
    moviePlayer.moviePlayer.shouldAutoplay=YES;


   moviePlayer.moviePlayer.movieSourceType= MPMovieSourceTypeFile;
    [moviePlayer.moviePlayer setControlStyle:MPMovieControlStyleDefault];

    [self.view addSubview:moviePlayer.view];

    [moviePlayer.moviePlayer play];

It is not playing the video and gives this error:

2013-12-08 22:31:00.497 UIWebViewVideoArge[684:60b] _itemFailedToPlayToEnd: {
    kind = 1;
    new = 2;
    old = 0;
}
onivi
  • 1,348
  • 3
  • 17
  • 25

1 Answers1

2

Url in your code:http://mywebsite.com/video.mp4 - not valid. With this url player produces an error like in your question. But if you try use another url (for example: http://nordenmovil.com/urrea/InstalaciondelavaboURREAbaja.mp4 - use it for test) your player will work without errors, but not correct. For correct work you must change your code:

add to your .h file in @interface section property (do not forget add @import MediaPlayer):

@property (nonatomic, strong) MPMoviePlayerViewController *moviePlayer;

and change your code like below:

  _moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:@"http://nordenmovil.com/urrea/InstalaciondelavaboURREAbaja.mp4"]];
  _moviePlayer.view.frame = CGRectMake(0, 0, 500, 500);
  _moviePlayer.moviePlayer.shouldAutoplay=YES;


  _moviePlayer.moviePlayer.movieSourceType= MPMovieSourceTypeFile;
  [_moviePlayer.moviePlayer setControlStyle:MPMovieControlStyleDefault];

  [self.view addSubview:_moviePlayer.view];

  [_moviePlayer.moviePlayer play];

As alternative you can use UIWebView for play video:

NSURL *fileURL = [NSURL URLWithString:@"http://nordenmovil.com/urrea/InstalaciondelavaboURREAbaja.mp4"];
NSURLRequest* requestUrl = [[NSURLRequest alloc] initWithURL:fileURL];
UIWebView* webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)];
[self.view addSubview:webView];
[webView loadRequest:requestUrl];

If you will use UIWebView for play video - try use your url and you will see what your link is wrong.

Ruslan Soldatenko
  • 1,718
  • 17
  • 25