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];
}
网友评论