2014-10-03 154 views
-1

在我的应用程序中,我需要从vimeo播放电影,这很好,但是我的洞应用程序仅适用于肖像。我想在特定的viewController中播放电影,并强制此控制器能够旋转为纵向或横向。IOS如何确定视频剪辑何时完成播放

当有人点击电影的缩略图时,我会选择到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; 
           }]; 

          } 
         }]; 
} 

回答

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. 
1

您需要在viewDidLoad中添加一个观察者,所以当你的视频会停止播放,让它执行你的方法。

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

这是接收器的方法,当视频停止播放

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