首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MPMoviePlayerController in UIView

MPMoviePlayerController in UIView
EN

Stack Overflow用户
提问于 2014-01-31 17:24:34
回答 2查看 2K关注 0票数 0

我正在创建一个iOS iPad应用程序,除其他外,它在一个屏幕上使用MPMoviePlayerController,在另一个名为“CommandMessageView”的视图下使用。下面是我的.h文件的相关部分:

代码语言:javascript
复制
@interface MovieViewController : UIViewController

@property (strong, nonatomic) MPMoviePlayerController *moviePlayer;
@property (strong, nonatomic) IBOutlet UIView *MovieView;
@property (strong, nonatomic) IBOutlet UIView *CommandMessageView;

然后是.m文件的相关部分:

代码语言:javascript
复制
@implementation MovieViewController

@synthesize MovieView;
@synthesize moviePlayer;
@synthesize CommandMessageView;

- (void)viewDidLoad {
     [super viewDidLoad];

// Video Setup

NSURL *currentVideoURL = [NSURL URLWithString:
              self.currentVideo];

moviePlayer =  [[MPMoviePlayerController alloc]
                 initWithContentURL:currentVideoURL];
moviePlayer.controlStyle = MPMovieControlStyleNone;
moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
[moviePlayer.view setFrame: MovieView.bounds];
moviePlayer.shouldAutoplay = NO;
[MovieView addSubview:moviePlayer.view];
[moviePlayer prepareToPlay];   
}

该视频播放良好,除非视图是旋转到纵向,在其中的视频放置在中屏幕,只有前2/3 (水平)是可见的。如果有帮助,可以在这里看到截图:

我所希望的是,为自动收费设置的UIView MovieView (几乎全屏)将定义视频可以容纳在其中的边界,以及正确的层(commandMessageView出现在其顶部)。显然,有些东西已经过时了,但在调整了许多选项之后,并没有留下任何回旋余地。我在这里/做错了什么明显的事情吗?或者在界面构建器中有什么需要修复的东西?谢谢你提前提供帮助!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-02-01 01:12:48

不确定这到底是如何工作的,但是添加了一行:

代码语言:javascript
复制
[moviePlayer.view setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];

就在

代码语言:javascript
复制
[moviePlayer.view setFrame: MovieView.bounds];

给了我想要的行为。

大家编码愉快!

票数 3
EN

Stack Overflow用户

发布于 2014-01-31 19:22:17

我也面临着一个类似的问题,除了图片。我想出来的是,你必须允许轮换,显然你已经做到了。

并实现如下内容:

代码语言:javascript
复制
 -(NSUInteger)supportedInterfaceOrientations{

//   if ([AppDelegate appDelegate].shoedAllowPortrait == YES) {
     // return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscape;
   return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationLandscapeLeft;

 //  }else{
  // return UIInterfaceOrientationMaskPortrait;
 //  }
  // return UIInterfaceOrientationMaskLandscape;
 }
    - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
  return UIInterfaceOrientationPortrait;
}
- (BOOL)shouldAutorotate{
 return YES;
 }

 -(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:       (NSTimeInterval)duration {

 [self.view setNeedsDisplay];

  }

原因是,每次设备旋转时,都需要刷新视图或moviePlayer视图。即使是托盘添加"viewDidRoatate“和刷新那里也是,这是不工作的。

希望这有帮助,干杯

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21486248

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档