2012-07-19 79 views
6

我只想知道當播放控件顯示或隱藏時是否有可能獲得通知?電影播放器​​控件顯示/隱藏時的通知?

例如,我想呈現視頻的風格:

self.moviePlayerController.controlStyle = MPMovieControlStyleEmbedded; 

當視頻開始播放時,播放控制變得可見,並自動消失。如果用戶只是選擇了視頻,則會出現控件。

我需要一個通知,所以我可以調整我的看法(重新定位MPMoviePlayerController視圖下的一些額外的按鈕。 這可能嗎?因爲不幸的是我沒有發現任何的文檔中。

回答

5

恐怕沒有記錄通知這些事件

你可能是幸運的,通過嗅探所有張貼的通知,如下面的答案找到的東西:

Trapping and tracing all notifications

How to receive NSNotifications from UIWebView embedded YouTube video playback


然而有一個辦法簡單地與那些MPMoviePlayerControler的鏈接您的控件。這種方式肯定是沒有文檔的,當它試圖在iTunes上銷售你的應用程序時,確實存在被拒絕的強烈風險。

首先,您需要找到MPMoviePlayerController範圍內的接口視圖,在使用嵌入式接口時,該視圖直到今天仍由類MPInlineVideoOverlay表示。請再次注意,由於蘋果可能會決定使用不同的命名方式,因此他的這一點很有可能會突破。

/** 
* This quirky hack tried to locate the interface view within the supposingly opaque MPMoviePlayerController 
* view hierachy. 
* @note This has a fat chance of breaking and/or getting rejected by Apple 
* 
* @return interface view reference or nil if none was found 
*/ 
- (UIView *)interfaceViewWithPlayer:(MPMoviePlayerController *)player 
{ 
    for (UIView *views in [player.view subviews]) 
    { 
     for (UIView *subViews in [views subviews]) 
     { 
      for (UIView *controlView in [subViews subviews]) 
      { 
       if ([controlView isKindOfClass:NSClassFromString(@"MPInlineVideoOverlay")]) 
       { 
        return controlView; 
       } 
      } 
     } 
    } 
    return nil; 
} 

如果返回正確的觀點,你只需要添加自己添加到界面上使用UIView addSubview: 一旦你這樣做,你的控制將是玩家的界面,顯示的一部分,並隱藏一起向右與它(也遵守所有動畫等)。

+1

旁註解釋了所提到的拒絕風險:我在一個主要的應用程序發佈中使用了這種精確的黑客攻擊,並且它未被發現...... – Till 2013-03-26 20:02:37

相關問題