2016-05-25 29 views
0

我认为编码完成按钮无法正常工作,因为当视频开始播放和视频播放完成时,我正在更改屏幕方向,因此我需要回到正常编辑状态。在iOS中完成视频更改方向

vid = [[MPMoviePlayerViewController alloc] initWithContentURL:url]; 
//[self presentModalViewController:vid animated:YES]; 
[self presentMoviePlayerViewControllerAnimated:vid]; 

NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft]; 
[[UIDevice currentDevice] setValue:value forKey:@"orientation"]; 
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(donebutton) name:MPMoviePlayerDidExitFullscreenNotification object:vid]; 

,然后编码完成按钮方法

-(void) donebutton{ 
    NSLog(@"done"); 
    NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait]; 
    [[UIDevice currentDevice] setValue:value forKey:@"orientation"]; 
} 
+0

您可以在“MPMoviePlayerPlaybackDidFinishNotification”方法中实现方向更改代码,以设置电影完成时的标准方向。 –

回答

0

希望这个代码将会帮助你改变设备的方向时,完成了视频播放。

-(void)playVideo { 
     moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url]; 

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

    [moviePlayer setFullscreen:YES animated:YES]; 
} 


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

moviePlayer = [notification object]; 
[[NSNotificationCenter defaultCenter] 
removeObserver:self 
name:MPMoviePlayerPlaybackDidFinishNotification 
object:moviePlayer]; 
// If the moviePlayer.view was added to full screen, it needs to be removed 

moviePlayer.fullscreen = NO; 

} 
+0

没有财产作为moviePlayer.fullscreen这是在我的情况vid.fullscreen没有这样的财产 – sahib

+0

它甚至没有达到的方法'moviePlaybackDidFinish' – sahib