2009-08-06 72 views
0

Iam嘗試播放來自遠程位置的視頻,並嘗試在整個屏幕上覆蓋一個窗口,該窗口或多或少都是透明的,邊緣上的圖像很少。一旦電影預先加載,我就播放視頻。第一次發生這種情況。但是,如果我嘗試重播視頻,它不會播放視頻,我也無法點擊播放器控件上的播放按鈕。我猜覆蓋窗口已經超過了控件。我如何獲得覆蓋窗口的控件?MPMoviePlayerController和覆蓋窗口

// - (空)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]; 

}

,我用的是

我是不是做錯了什麼的代碼。是否有可能通過覆蓋控制或自動播放它。

回答

0

兩件事。 首先,根據您的代碼,在moviePlayBackDidFinish方法中,您必須首先釋放moviePlayer,然後使用alloc再次實例化它。每次你想播放視頻都必須這樣做。

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

你的代碼結構的工作原理,但我認爲你最好看一下由蘋果提供的示例: http://developer.apple.com/iphone/library/samplecode/MoviePlayer_iPhone/index.html

二,關於覆蓋,你是對的,覆蓋得到事件,但你不能把它放在電影播放器​​的控制下。你必須做的是使用你的覆蓋層中收到的事件來控制播放器。您可以使用touchesBegan事件傳遞初始觸摸事件並將其用於播放器(播放,暫停,停止)。