xcode 横向全屏播放视频 (iPhone)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4740101/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 20:07:02  来源:igfitidea点击:

Play videos fullscreen in landscape (iPhone)

iphoneobjective-cxcode

提问by Buyin Brian

I have an app that is built as a hierarchy of viewControllers.

我有一个构建为 viewControllers 层次结构的应用程序。

On of the view Controllers is for a 'video section' of the app.

视图控制器中的一个用于应用程序的“视频部分”。

The app is designed to be portrait only, however, I want to force the videos to play fullscreen in landscape (just like the iPod app on the iPhone).

该应用程序仅设计为纵向模式,但是,我想强制视频以横向方式全屏播放(就像 iPhone 上的 iPod 应用程序一样)。

After searching around, I see that many people have this problem.

找了一圈,发现很多人都有这个问题。

I finally have been able to rotate it, but it doesn't work in full screen, that defaults to portrait.

我终于能够旋转它,但它不能在全屏模式下工作,默认为纵向。

And since it doesn't work in full screen, you see elements in the parent views over the video.

由于它不能在全屏模式下工作,您可以在视频的父视图中看到元素。

Is there an easy way to rotate this video in full screen, or do I have to broadcast a message to the parent views to hide elements when the video is playing?

是否有一种简单的方法可以全屏旋转此视频,或者我是否必须在播放视频时向父视图广播消息以隐藏元素?

here is the code:

这是代码:

    NSURL *url = [NSURL URLWithString:[recipeData objectForKey:@"videoPath"]];

    MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];  

    // Register to receive a notification when the movie has finished playing.  
    [[NSNotificationCenter defaultCenter] addObserver:self  
                                             selector:@selector(moviePlayBackDidFinish:)  
                                                 name:MPMoviePlayerPlaybackDidFinishNotification  
                                               object:moviePlayer];  


        moviePlayer.controlStyle =   MPMovieControlStyleFullscreen;
        moviePlayer.scalingMode = MPMovieScalingModeAspectFill;
        moviePlayer.shouldAutoplay = YES;  
        moviePlayer.view.frame = [[UIScreen mainScreen] applicationFrame];
        moviePlayer.view.transform = CGAffineTransformMakeRotation(1.57079633);
        moviePlayer.view.bounds = CGRectMake(0.0, 0.0, 480, 320);

        [self.view addSubview:moviePlayer.view];  
//commenting out the line below will rotate the video, leaving it uncommented forces it to play fullscreen in portrait
        [moviePlayer setFullscreen:YES animated:NO];  

采纳答案by Buyin Brian

I put the method to create the video in the appDelegate and target it whenever the video is launched. This did the trick, keeping it above everything else.

我将创建视频的方法放在 appDelegate 中,并在视频启动时定位它。这做到了,让它高于一切。

回答by Hivebrain

For full screen playback you should use MPMoviePlayerViewController and then to make it launch and play in landscape format use the "shouldAutorotateToInterfaceOrientation" method on the MPMoviePlayerViewController class.

对于全屏播放,您应该使用 MPMoviePlayerViewController,然后使用 MPMoviePlayerViewController 类上的“shouldAutorotateToInterfaceOrientation”方法以横向格式启动和播放。

Looks like this:

看起来像这样:

[yourInstanceOfMPMoviePlayerViewController shouldAutorotateToInterfaceOrientation: UIInterfaceOrientationLandscapeRight];

回答by Jesse Naugher

Have you tried using MPMoviePlayerViewControllerinstead? it presents a full screen almost modal view Controller to handle the video playing. I use it in >=3.2 version and use a hacked up version of MPMoviePlayerControllerfor <3.2

您是否尝试过使用MPMoviePlayerViewController?它呈现了一个全屏几乎模态视图控制器来处理视频播放。我在 >=3.2 版本中使用它,并MPMoviePlayerController在 <3.2 中使用了 hacked 版本