MPMoviePlayer not playing video
Asked Answered
A

3

8

MPMoviePlayer is not playing video. I'm running iOS 7 and getting the same error on the device and simulator:

2013-10-02 12:49:18.246 xxxx[688:60b] _itemFailedToPlayToEnd: {
kind = 1;
new = 2;
old = 0;

}

I've tried playing a video from the internet and file system, but no luck. My code is very straightforward:

    self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:@"http://stream.qtv.apple.com/events/mar/123pibhargjknawdconwecown/12oihbqeorvfhbpiubqnfv3_650_ref.mov"]];
    self.moviePlayer.view.frame = self.view.bounds;
    self.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
    [self.view addSubview:self.moviePlayer.view];
    [self.moviePlayer prepareToPlay];

The URL listed is a valid movie: http://stream.qtv.apple.com/events/mar/123pibhargjknawdconwecown/12oihbqeorvfhbpiubqnfv3_650_ref.mov

I've also tried using MPMoviePlayerViewController, but that didn't work either.

Afterglow answered 2/10, 2013 at 18:1 Comment(1)
see #22069181Dulsea
R
3

MPMovieSourceTypeStreaming seems to be buggy on iOS 7. On my app, I'm streaming a video from the web (same as you), and the problem disappear with this source type :

self.moviePlayer.movieSourceType = MPMovieSourceTypeFile;

I know it's strange because we're streaming the video, but this is the only solution that works for me.

Hope it helps :)

Raddie answered 26/11, 2013 at 12:27 Comment(0)
D
1

1.change the mov file to mp4 file,it seems that the player can't support the mov file

2.delete the code self.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;

or change to self.moviePlayer.movieSourceType = MPMovieSourceTypeFile;

3.add code [self.moviePlayer setFullscreen:YES]; after [self.view addSubview:self.moviePlayer.view];

note:You must note the sequence,otherwise you can only hear the sound but can't watch the movie

If you want to use MPMoviePlayerViewController,like this:

 MPMoviePlayerViewController *moviePlayerViewController;
   moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:@"http://.../movie.mp4"]];//note:mp4 file
    [self presentMoviePlayerViewControllerAnimated:moviePlayerViewController];

Important:If the URL is error,you will also get the same error. eg:this is wrong

moviePlayer=[[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:@"movie.mp4"]];

to correct it:

If the URL is a web URL,then like this:

moviePlayer=[[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:@"http://..../movie.mp4"]];

else if the file is a local file,then like this:

moviePlayer=[[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"movie" ofType:@"mp4”]]];
Dagall answered 2/4, 2014 at 1:4 Comment(0)
C
0

Try this and sorry for the late reply :

NSURL    *fileURL    =   [NSURL URLWithString:@"file  url from the internet "];
    MPMoviePlayerViewController *moviePlayerController = [[MPMoviePlayerViewController alloc] initWithContentURL:fileURL];

    [moviePlayerController.moviePlayer setFullscreen:YES animated:YES];
    [moviePlayerController.moviePlayer.view setFrame: self.view.bounds];
    [moviePlayerController.moviePlayer setControlStyle:MPMovieControlStyleFullscreen];
    [moviePlayerController.moviePlayer setMovieSourceType:MPMovieSourceTypeFile];

    [self presentMoviePlayerViewControllerAnimated:moviePlayerController];
    [moviePlayerController.moviePlayer prepareToPlay];
    [moviePlayerController.moviePlayer play];
Commendation answered 12/11, 2013 at 12:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.