IOS如何确定视频剪辑何时播放完毕

时间:2014-10-03 14:38:08

标签: ios objective-c iphone xcode video

在我的应用程序中,我需要从vimeo播放电影,这很好,但我的洞应用程序仅用于肖像。我想在特定的viewController中播放电影并强制此控制器能够旋转到纵向或横向。

当有人点击电影的缩略图时,我会看到VideoViewController,我需要知道如何确定这部电影剪辑何时完成,这样我就可以在视频完成后直接将它们反过来。

代码;

@implementation VideoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    [self vimeoVideo];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)vimeoVideo
{
    [YTVimeoExtractor fetchVideoURLFromURL:@"http://vimeo.com/1071123395"
                         quality:YTVimeoVideoQualityMedium
                         referer:@"http://xxxxx.com"
                         completionHandler:^(NSURL *videoURL, NSError *error, YTVimeoVideoQuality quality) {
                             if (error) {
                                 // handle error
                                 NSLog(@"Video URL: %@", [videoURL absoluteString]);
                             } else {
                                 // run player
                                 self.playerView = [[MPMoviePlayerViewController alloc] initWithContentURL:videoURL];
                                 [self.playerView.moviePlayer prepareToPlay];
                                 [self presentViewController:self.playerView animated:YES completion:^(void) {
                                 self.playerView = nil;
                                 }];

                             }
                         }];
}

2 个答案:

答案 0 :(得分:1)

你需要在viewDidLoad上添加一个观察者,这样当你的视频停止播放时,让它执行你的方法。

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:playerView];

这是视频停止播放时的接收方法

- (void)moviePlayerDidFinish:(NSNotification *)notification
{
    //Do your stuff
}

答案 1 :(得分:0)

MPMoviePlayerController中,有可供您使用的通知列表。你需要的是MPMoviePlayerPlaybackDidFinishNotification

Posted when a movie has finished playing. The userInfo dictionary of this notification contains the MPMoviePlayerPlaybackDidFinishReasonUserInfoKey key, which indicates the reason that playback finished. This notification is also sent when playback fails because of an error.