MPMoviePlayer解雇按下时
-
22-09-2019 - |
题
我有一个MPMoviePlayer的设置发挥介绍电影我应用程序。这工作只是伟大的、唯一的问题是,它持续的时间为14秒钟,我想要给我用一个机会,以跳过介绍按上的任何地方的电影。
我有隐藏的影控制,因为它们是不必要的。
代码:
NSString *introPath = [[NSBundle mainBundle] pathForResource:@"intro" ofType:@"mov"];
intro = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:introPath]];
[intro setMovieControlMode:MPMovieControlModeHidden];
[intro play];
谢谢你!
解决方案
编辑:我最初的解决方案不会的工作,因为电影中所示的第二个窗口,层次上应用程序的主要窗口(这是非常罕见到有多于一个窗口观层次上的iPhone).这个方案基础上 苹果MoviePlayer代码样本, 不工作:
. . .
// assuming you have prepared your movie player, as in the question
[self.intro play];
NSArray* windows = [[UIApplication sharedApplication] windows];
// There should be more than one window, because the movie plays in its own window
if ([windows count] > 1)
{
// The movie's window is the one that is active
UIWindow* moviePlayerWindow = [[UIApplication sharedApplication] keyWindow];
// Now we create an invisible control with the same size as the window
UIControl* overlay = [[[UIControl alloc] initWithFrame:moviePlayerWindow.frame]autorelease];
// We want to get notified whenever the overlay control is touched
[overlay addTarget:self action:@selector(movieWindowTouched:) forControlEvents:UIControlEventTouchDown];
// Add the overlay to the window's subviews
[moviePlayerWindow addSubview:overlay];
}
. . .
// This is the method we registered to be called when the movie window is touched
-(void)movieWindowTouched:(UIControl*)sender
{
[self.intro stop];
}
NB:你必须保存的参考电影放在一个实例中的变量,这是最方便的声明一个酒店,我们可以用它来进行访问。这就是为什么使用 self.intro
而不是只是 intro
在例子。如果你不知道如何申报的一个实例变量和一个酒店,有很多的信息,对这个网站和其他地方。
****原来回答下面
(不工作,在这种情况,但在许多类似的方案,因此我将把它作为一个预警和/或鼓舞人心的例子。)
...如果没有别的工作,我建议你继承UIWindow和确保应用程序委托的实例,而不是一个正常的UIWindow.你可以拦截涉及在这类发送的通知或取消电影的直接(如果你已经储存的指针MPMoviePlayer在ivar在你的窗子类).
@interface MyWindow : UIWindow {
}
@end
@implementation MyWindow
// All touch events get passed through this method
-(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
// The screen has been touched, send a notification or stop the movie
return [super hitTest:point withEvent:event];
}
@end
不隶属于 StackOverflow