如何应用条件以全屏播放视频并在特定帧中播放

时间:2011-05-16 08:58:21

标签: iphone objective-c ipad mpmovieplayercontroller

我默认全屏播放视频:

Play video by default in full screen

但是使用此代码可以最大限度地减少控制。

我的确切要求是:

由于视图将加载视频将默认以全屏播放,并且当它将被最小化时,它应该在特定帧中播放。 当它结束时我想写一些代码,但是什么条件将适用于检查视频是否完成/结束?

Plz帮助我。

感谢。

3 个答案:

答案 0 :(得分:1)

当你分配你的moviePlayer对象时添加下面的通知:

[[NSNotificationCenter defaultCenter] addObserver:self 
                                     selector:@selector(moviePlayBackDidFinish:) 
                                         name:MPMoviePlayerPlaybackDidFinishNotification 
                                       object:moviePlayer];

因此,当您的视频完成播放或者您将完成后,将完成以下方法:

- (void)moviePlayBackDidFinish:(NSNotification*)notification 
{
// write your code here
}

答案 1 :(得分:0)

您需要注册以下通知

[[NSNotificationCenter defaultCenter] addObserver:self 
                                         selector:@selector(movieLoaded:) 
                                             name:MPMoviePlayerLoadStateDidChangeNotification 
                                           object:moviePlayer];


[[NSNotificationCenter defaultCenter] addObserver:self 
                                         selector:@selector(moviePlayBackDidFinish:) 
                                             name:MPMoviePlayerPlaybackDidFinishNotification 
                                           object:moviePlayer];

然后按如下方式实现消息:

- (void)movieLoaded:(NSNotification*)notification 
- (void)moviePlayBackDidFinish:(NSNotification*)notification 

答案 2 :(得分:0)

嗨使用它的工作正常

AVAsset *aset=[AVAsset assetWithURL:url];
AVPlayerItem *item=[[AVPlayerItem alloc]initWithAsset:aset];
play=[[AVPlayer alloc]initWithPlayerItem:item];
AVPlayerLayer *layer=[[AVPlayerLayer alloc]init];
layer.player=play;;
layer.frame=CGRectMake(200, 250, 400, 250);
[self.view.layer addSublayer:layer];

[play play];