2016-05-25 12 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

私の場合はvid.fullscreenのmoviePlayer.fullscreenプロパティはありません。そのようなプロパティはありません – sahib

+0

そのメソッドにも達しません 'moviePlaybackDidFinish' – sahib

関連する問題