我必须播放.m3u8格式的网址视频

时间:2015-06-10 04:14:23

标签: ios objective-c mpmovieplayercontroller

我尝试过以下代码,但这不起作用。只有黑屏作为输出。

    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 个答案:

答案 0 :(得分:1)

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;
}

答案 1 :(得分:0)

尝试更改此行:

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

这一行:

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