MPMoviePlayerViewController视频播放三

2016-10-26  本文已影响79人  Loki_

1、导入MediaPlayer.framework框架

2、播放视频

MPMoviePlayerViewController*desViewController = [[MPMoviePlayerViewControlleralloc] initWithContentURL:[NSURLURLWithString:@视频网络地址]];

[desViewController.moviePlayerprepareToPlay];

[self presentMoviePlayerViewControllerAnimated:desViewController];

[desViewController.viewsetBackgroundColor:[UIColorclearColor]];

[desViewController.viewsetFrame:self.view.bounds];

[[NSNotificationCenter defaultCenter] addObserver:selfselector:@selector(movieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:desViewController.moviePlayer];

3、结束播放

-(void)movieFinishedCallback:(NSNotification*)notify{

//视频播放完或者在presentMoviePlayerViewControllerAnimated下的Done按钮被点击响应的通知。

MPMoviePlayerController* theMovie = [notifyobject];

[[NSNotificationCenter defaultCenter]removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:theMovie];

[self dismissMoviePlayerViewControllerAnimated];

}

上一篇下一篇

猜你喜欢

热点阅读