使用叠加视图制作 MPMoviePlayer 的更好方法

发布于 2024-11-03 09:14:25 字数 495 浏览 1 评论 0原文

当我们使用 MPMoviePlayer (在自定义 UIViewController 内)创建应用程序并在电影播放器​​之上覆盖 UIViewController 时,更好的是: - 使用 self.view.presentModalView... 或 self.view.addSubView... 在播放器中加载电影 或者有没有其他更好的办法。我现在使用模态视图,除了必须实现一些自定义旋转之外,一切正常。我正在寻找更清晰的方法来做到这一点。

好吧,也许还有更多细节。在 iPhone 应用程序中,我添加了类似模态视图的播放器,并向其中添加了覆盖视图,这样就可以了。但这是通用应用程序,它在 iPad 上的工作方式与在 iPhone 上的工作方式不同。在 ipad splitView 中,我的播放器位于详细信息侧(非全屏),当我双击播放器时,它会进入全屏。现在播放器是关键窗口。这是最大的问题。我尝试将叠加视图添加为子视图和模态视图,并且我做到了,但是该叠加不知道设备方向,并且我必须转换叠加元素,这就是我试图避免的。有什么方法可以检测该视图上的旋转吗?

When we creating application with MPMoviePlayer (within custom UIViewController) and with overlay UIViewController on top of movie player what is better:
- Load movie in player with self.view.presentModalView... or self.view.addSubView...
Or is there any other better way. I now work with modal views and everything works except I have to implement some custom rotations. I am looking for more clear way to make this.

Ok maybe some more details. In iPhone app I add player like modal view and add overlay view to it and that works. But this is universal app and it doesn't work on iPad the same way it works on iPhone. In ipad splitView my player is on details side (nonfullscreen), when I double tap player it goes fullscreen. And now player is key window. Here is the biggest issue. I tried to add overlay view as subviw and modal view and I made it but that overlay is not aware of device orientation, and I have to transform overlay elements and this is what I am trying to avoid. Is there any way to detect rotation on that view?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

夏九 2024-11-10 09:14:25

简单且最优雅的解决方案:

不要使用“真实”全屏模式,而是将 MPMoviePlayerController 的视图缩放到屏幕填充大小 - MPMoviePlayerController.view.frame = CGRectMake(0.0f, 0.0f, 768.0f, 1024.0f) ;。将 MPMoviePlayerControllerview 保持在允许旋转 (addSubview) 的常规 UIViewControllerview 之上。将您的自定义界面视图保持在 MPMoviePlayerController 视图 (addSubview) 之上,很快,无论您是否以“全屏”运行,您都将获得一个正确旋转的视频播放器。

Simple and most elegant solution:

Do not use the "real" fullscreen mode but scale the MPMoviePlayerController's view towards a screen-filling size - MPMoviePlayerController.view.frame = CGRectMake(0.0f, 0.0f, 768.0f, 1024.0f);. Keep the MPMoviePlayerController's view on top of a regular UIViewController's view that allows rotations (addSubview). Keep your custom interface view on top of the MPMoviePlayerController's view (addSubview) and presto, you will get a properly rotating video player no matter if you run it in "fullscreen" or not.

初熏 2024-11-10 09:14:25

我找到了一个解决方案,但我不是很自豪,因为我认为有更好的方法,但这种解决方法有效:
- 在项目中,我有一个单例类,其中包含一些全局数据。
- 当应用程序在详细视图 (UISplitView) 中启动时,首先调用 willAnimateRotationToInterfaceOrientation 方法。在这里,我获取当前方向并将其存储在单例类中。
- 后来,当我在播放器顶部添加覆盖时,我从单例读取数据并转换覆盖元素。

I found one solution but I am not very proud because I this that there is some better way, but this workaround works:
- In project I have on singleton class that contains some global data for me.
- When application start in detail view (UISplitView) willAnimateRotationToInterfaceOrientation method is called first. Here I get current orientation and store it in singleton class.
- Later when I add overlay on top of player I read data from singleton and transform overlay elements.

旧伤还要旧人安 2024-11-10 09:14:25

根据上面我做了这样的事情:

mp = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:@"http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"]];

mp.movieSourceType = MPMovieSourceTypeStreaming;

mp.view.frame = CGRectMake(0.0f, 0.0f, 1024.0f, 768.0f);

[self.view addSubview:mp.view];

mp.controlStyle = MPMovieControlStyleNone;

[self.view addSubview:self.myOverlay];


[mp play];

其实这很简单!只需将控制样式选择为“无”,然后在播放器视图上添加低不透明度视图即可。

According to above I did something like this:

mp = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:@"http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"]];

mp.movieSourceType = MPMovieSourceTypeStreaming;

mp.view.frame = CGRectMake(0.0f, 0.0f, 1024.0f, 768.0f);

[self.view addSubview:mp.view];

mp.controlStyle = MPMovieControlStyleNone;

[self.view addSubview:self.myOverlay];


[mp play];

Actually it was so easy! Just choose control style to None and add your low opacity view on the player view.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文