自定义UIView来显示视频

发布于 2024-10-01 05:55:55 字数 355 浏览 1 评论 0原文

嘿大家, 我正在开发一款适用于 iPad 的应用程序,并且遇到了一个问题,需要一些指导。我有一个使用 TabBarController 的应用程序。 TabBarController 包含 4 个 UIViewController...应用程序中的每个屏幕一个。在这 4 个屏幕中的每一个上,都有 4 个图块需要充当按钮并在单击时播放视频。我想在悬停在屏幕其余部分上的视图中播放视频,如果用户触摸正在播放的视频之外的任何位置,该视图就会消失。

我的问题是:如何实现自定义视图来播放视频?在我看来,它应该只是带有 viewController 的另一个视图......但我不知道这是否是正确的方法。另外,如何让它根据单击的按钮播放正确的视频? 非常感谢任何建议。 谢谢 亚历克斯

Hey All,
Im working on an app for the iPad and Ive run across an issue that I need some guidance on. I have an app that uses the TabBarController. The TabBarController contains 4 UIViewController...one for each screen in the app. On each of these 4 screens, there are 4 tiles that need to act as buttons and play a video when clicked. I would like to play the video in a view that hovers over the rest of the screen and is dismissed if the user touches anywhere outside the playing video.

My question is: How do I go about implementing the custom view to play the video? It seems to me that it should be just another view with a viewController...but I dont know if that is the correct way to go about this. Also, how do I get it to play the right video depending on what button was clicked?
Any advice is greatly appreciated.
Thanks
Alex

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

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

发布评论

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

评论(1

涫野音 2024-10-08 05:55:55

我不确定我是否完全明白问题所在,如果我的答案不够,请更准确。

首先初始化视频播放器视图控制器类 MPMoviePlayerController,然后您可以使用它的 .view 属性或容器视图执行任何您想要的操作以显示 4 个按钮。

NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:@"someMovie" ofType:@"m4v"];

MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:url]];
player.view.frame = CGRectMake(someX, someY, someWidth, someHeight);

[self.view addSubview:player.view];
[player play];

I'm not sure if I entirely get what the question is, if my answer is not enough please be more precise.

first you initialize your video player view controller class MPMoviePlayerController, then you can do whatever you want with it's .view property, or the container view to display your 4 buttons.

NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:@"someMovie" ofType:@"m4v"];

MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:url]];
player.view.frame = CGRectMake(someX, someY, someWidth, someHeight);

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