Pregunta

I'm trying to play a video with MPMoviePlayerController over HTTP Live Streaming (with Adobe Media Server).

- (void) viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    [self playVideo];
}

- (void) playVideo{
    NSURL *url = [NSURL URLWithString:@"http://192.168.10.27/hls-vod/test.mp4.m3u8"];
    MPMoviePlayerController *moviePlayer =
    [[MPMoviePlayerController alloc] initWithContentURL:url];
    moviePlayer.controlStyle = MPMovieControlStyleDefault;
    [self.view addSubview:moviePlayer.view];
    [moviePlayer setFullscreen:YES animated:YES];
    [moviePlayer play];
}

The player is launching correctly, but it's still loading and doesn't start playing the video. I tried some links on Safari under my device and it works correctly!

Do you have any idea about that problem?

¿Fue útil?

Solución

I found the solution ! I just have to declare the moviePlayer in the interface of the controller and initiate it an the playVideo method and it's worked !

Otros consejos

  1. Did you attempt on a real device? Sometimes MPMoviePlayerControllers won't play properly in the simulator.

  2. Are you creating more than one MPMoviePlayerController at a time? You can only have one MPMoviePlayerController instantiated, so if you need to play a second video, the first must be either destroyed or reused.

  3. An m3u8 file is a playlist, not a video file, so take a look in the file and make sure it's pointing to file types that are supported by MPMoviePlayerController.

Also: note that you're playing the video in the viewDidAppear method. Please note that this will get called any time the user exits full screen on the MPMoviePlayerController, so you may want to include more logic there to decide whether to show it. (Unless you always want to show it forever.)

(FIXED!!!!!)

I encountered this problem earlier.

And the problem was due to static player. Try using a property of MPMoviewPlayer

sample code looks like this:

@interface YourViewController ()
@property (nonatomic, strong) MPMoviewPlayer *mp;
@end

@implementation YourViewController
- (void)playVideo {
    NSURL *movieURL = [NSURL URLWithString:@"http://the/url/playlist.m3u8"];
    self.mp = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];

    if (self.mp)
    {
        self.mp.view.frame = self.view.bounds;
        [self.view addSubview:self.mp.view];

        // save the movie player object
        [self.mp setFullscreen:YES];

        // Play the movie!
        [self.mp play];
    }
}

@end
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top