MPMoviePlayer 按下时关闭
我有一个 MPMoviePlayer 设置来为我的应用程序播放介绍影片。这效果很好,唯一的问题是它持续 14 秒,我想让我的用户有机会通过按电影上的任意位置来跳过介绍。
我隐藏了电影控件,因为不需要它们。
代码:
NSString *introPath = [[NSBundle mainBundle] pathForResource:@"intro" ofType:@"mov"];
intro = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:introPath]];
[intro setMovieControlMode:MPMovieControlModeHidden];
[intro play];
谢谢!
I have a MPMoviePlayer setup to play an intro movie to my application. That works just great, the only problem is that it lasts for 14 seconds, and I want to give my users a chance to skip the intro by pressing anywhere on the movie.
I have hidden the movie controls, as they are not needed.
Code:
NSString *introPath = [[NSBundle mainBundle] pathForResource:@"intro" ofType:@"mov"];
intro = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:introPath]];
[intro setMovieControlMode:MPMovieControlModeHidden];
[intro play];
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编辑:我最初的解决方案不起作用,因为电影在第二个窗口中显示,位于应用程序主窗口的顶部(iPhone 上的视图层次结构中很少有多个窗口)。此解决方案基于 Apple 的 MoviePlayer 示例代码,确实有效:
注意:您必须将对电影播放器的引用保存在实例变量中,并且声明一个我们可以用来访问它的属性是最方便的。这就是为什么在示例中使用
self.intro
而不是仅使用intro
。如果您不知道如何声明实例变量和属性,可以在本网站和其他地方找到大量信息。**** 下面的原始答案
(在这种情况下不起作用,但在许多类似的情况下,所以我将其作为警告和/或鼓舞人心的示例。)
。 。 。如果没有其他工作,我建议子类化 UIWindow 并确保您的应用程序委托实例化它而不是普通的 UIWindow。您可以拦截该类中的触摸并发送通知或直接取消影片(如果您已在窗口子类的 ivar 中存储了指向 MPMoviePlayer 的指针)。
EDIT: My initial solution won't work, because the movie is shown in a second window, layered on top of the app's main window (it's very rare to have more than one window in the view hierarchy on the iPhone). This solution, based on Apple's MoviePlayer sample code, does work:
NB: You must save the reference to the movie player in an instance variable, and it's most convenient to declare a property that we can use to access it. That's why is use
self.intro
instead of justintro
in the example. If you don't know how to declare an instance variable and a property, there is plenty of information on this site and elsewhere.**** ORIGINAL ANSWER BELOW
(Doesn't work in this case, but in many similar scenarios, so I'll leave it as a warning and/or inspiring example.)
. . . if nothing else works I'd recommend subclassing UIWindow and making sure that your app delegate instantiates that instead of a normal UIWindow. You can intercept touches in that class and send a notification or cancel the movie directly (if you've stored a pointer to the MPMoviePlayer in an ivar on your window subclass).