MPMoviePlayerController的用法(简单用法)
//添加通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(finishPlay) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(stateChange) name:MPMoviePlayerPlaybackStateDidChangeNotification object:nil];
NSURL *url = [NSURL URLWithString:@"http://vf1.mtime.cn/Video/2012/04/23/mp4/120423212602431929.mp4"];
playerCtrl = [[MPMoviePlayerController alloc] initWithContentURL:url];
//修改视频播放器的控制样式
/*
MPMovieControlStyleNone, // No controls
MPMovieControlStyleEmbedded, // Controls for an embedded view
MPMovieControlStyleFullscreen, // Controls for fullscreen playback
MPMovieControlStyleDefault = MPMovieControlStyleEmbedded
*/
playerCtrl.controlStyle = MPMovieControlStyleEmbedded;
//设置播放器的大小
playerCtrl.view.frame = CGRectMake(0, 150, 360, 300);
[self.view addSubview:playerCtrl.view];
[playerCtrl play];
}
- (IBAction)btnClick:(id)sender {
MPMoviePlayerViewController播放视频
NSURL *url = [NSURL URLWithString:@"http://vf1.mtime.cn/Video/2012/04/23/mp4/120423212602431929.mp4"];
MPMoviePlayerViewController *playerViewCtrl = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
[self presentViewController:playerViewCtrl animated:YES completion:nil];
}
- (void)finishPlay
{
NSLog(@"播放完成");
}
- (void)stateChange
{
/*
MPMoviePlaybackStateStopped,
MPMoviePlaybackStatePlaying,
MPMoviePlaybackStatePaused,
MPMoviePlaybackStateInterrupted,
MPMoviePlaybackStateSeekingForward,
MPMoviePlaybackStateSeekingBackward
*/
MPMoviePlaybackState state = playerCtrl.playbackState;
if (state == MPMoviePlaybackStateStopped) {
NSLog(@"停止");
}else if (state == MPMoviePlaybackStatePaused) {
NSLog(@"暂停");
}else if (state == MPMoviePlaybackStateSeekingForward) {
NSLog(@"快进");
}else if (state == MPMoviePlaybackStateSeekingBackward) {
NSLog(@"快退");
}
}