2014-10-03 163 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 
}