MPMoviePlayerController和叠加窗口

时间:2009-08-06 18:35:40

标签: iphone

Iam尝试从远程位置播放视频并尝试在整个屏幕上叠加一个窗口,该窗口或多或少是透明的,沿边缘的图像很少。电影预装后我立即播放视频。第一次发生这种情况很好。但是,如果我尝试重放视频,它就不播放视频,也无法点击播放器控件上的播放按钮。我猜覆盖窗口在控件之上。如何获得覆盖窗口上的控件。

// - (void)moviePlayerContentPreloadDidFinish:(NSNotification *)通知{

NSLog(@"content preloaded");
NSDictionary *userInfo = [notification userInfo];
if ([userInfo valueForKey:@"error"]) {
    NSLog(@"*** An error occurred preloading the movie");
    return;
}

[self.spinner stopAnimating];

// Add the overlay view to the movie, so we can catch the clicks
OverlayViewController *ovc = [[OverlayViewController alloc] initWithNibName:@"OverlayView" bundle:nil];
self.overlayController = ovc;
[ovc release];
[self.overlayController setNextResponder:self];

MPMoviePlayerController *moviePlayer = [notification object];   


[moviePlayer play];

// Locate the movie player window
NSArray *windows = [[UIApplication sharedApplication] windows];
NSLog(@"window count= %d",[windows count]);
if ([windows count] < 2) {
    NSLog(@"*** Window for movie player is missing");
    return;
}

UIWindow *moviePlayerWindow = [windows objectAtIndex:1];
[moviePlayerWindow addSubview:self.overlayController.view];

}

我使用的代码是

我做错了什么。是否可以对叠加层进行控制或自动播放。

1 个答案:

答案 0 :(得分:0)

两件事。 首先,根据您的代码,在moviePlayBackDidFinish方法中,您必须首先释放moviePlayer,然后使用alloc再次实例化它。每次想要播放视频时都必须这样做。

MPMoviePlayerController *moviePlayer = [notification object];
[moviePlayer release]
...
MPMoviePlayerController *newMoviePlayer = [[MPMoviePlayerController alloc] initWithContentURL: anURL];

您的代码结构有效,但我认为您应该更好地查看apple提供的示例: http://developer.apple.com/iphone/library/samplecode/MoviePlayer_iPhone/index.html

其次,关于叠加层,你是对的,叠加层获取事件,但你不能把它放在电影播放器​​控制之下。您需要做的是使用叠加中收到的事件来控制播放器。您可以使用touchesBegan事件来传递初始触摸事件并将其与播放器一起使用(播放,暂停,停止)。

相关问题