i have to play a video from a url which is in .m3u8 format

230 views Asked by At

I have tried the following code but this is not working. only a black screen is coming out as output.

    NSURL *url_vdo=[[NSURL alloc] initWithString:@"url"];
    moviePlayer=[[MPMoviePlayerController alloc] initWithContentURL:url_vdo];

    [moviePlayer.view setFrame: self.view.bounds];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDonePressed:) name:MPMoviePlayerDidExitFullscreenNotification object:moviePlayer];
    moviePlayer.controlStyle=MPMovieControlStyleFullscreen;
    [moviePlayer play];
    [moviePlayer setFullscreen:YES animated:YES];

    [self.view addSubview:moviePlayer.view];
2

There are 2 answers

1
Akshay Karanth On
NSURL *movieURL = [NSURL URLWithString:@"http://url.m3u8"];
MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];

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

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

    // Play the movie!
    [mp play];

    self.moviePlayer = mp;
}
0
ridvankucuk On

Try to change this line:

[moviePlayer.view setFrame: self.view.bounds];

With this line:

[moviePlayer.view setFrame: self.view.frame];