2014-10-02 70 views

回答

9

通過偵聽AVPlayerItemBecameCurrentNotification通知,您可能會採取這種做法。當UIWebView顯示媒體播放器時觸發此通知,併發送一個AVPlayerItem作爲通知的對象。

例如:

[[NSNotificationCenter defaultCenter] addObserver:self 
             selector:@selector(playerItemBecameCurrent:) 
              name:@"AVPlayerItemBecameCurrentNotification" 
              object:nil]; 


-(void)playerItemBecameCurrent:(NSNotification*)notification { 
    AVPlayerItem *playerItem = [notification object]; 
    if(playerItem == nil) return; 
    // Break down the AVPlayerItem to get to the path 
    AVURLAsset *asset = (AVURLAsset*)[playerItem asset]; 
    NSURL *url = [asset URL]; 
    NSString *path = [url absoluteString]; 
} 

這適用於任何視頻(音頻)。然而,我注意到你提到的YouTube - 值得指出的是蘋果拒絕你的應用程序,如果它有能力下載YouTube視頻在所有,因爲它不符合YouTube's Terms of Service

+0

謝謝,它的工作。即使我無法獲得與視頻對應的當前網址。是否有任何方法? – Jeff 2014-10-02 06:07:28

+0

@Jeff你是什麼意思?我上面的示例代碼顯示獲取URL作爲NSURL和NSString。這是正在播放的視頻的網址。 – ttarik 2014-10-02 06:10:45

+0

我正在編碼的url.I問關於視頻的youtube鏈接 – Jeff 2014-10-02 06:15:37

相關問題