【问题标题】:change orientation when video is finished in iOS在 iOS 中完成视频时更改方向
【发布时间】:2016-05-25 23:38:52
【问题描述】:

我认为我在完成按钮上的编码不起作用,因为我在视频开始时更改屏幕方向,当视频结束时我需要回到我的正常方向我的编码是。

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"];
}

【问题讨论】:

  • 你可以在“MPMoviePlayerPlaybackDidFinishNotification”方法中实现方向改变代码来设置电影结束时的正常方向。

标签: ios objective-c uiinterfaceorientation


【解决方案1】:

希望这段代码可以帮助您在视频播放完成后更改设备方向。

-(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;

}

【讨论】:

  • 没有像moviePlayer.fullscreen这样的属性,在我的例子中是vid.fullscreen没有这样的属性
  • 它甚至没有达到方法moviePlaybackDidFinish
猜你喜欢
  • 1970-01-01
  • 2023-01-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多