我有這個應用程序(由以前的工友寫的),它調用視頻網站來顯示視頻列表,當用戶點擊一個視頻時,應用程序會自動創建一個MPMoviePlayer並播放視頻。如何在UIWebview中的播放器中獲取MPMoviePlayerPlaybackStateDidChangeNotification?
我被要求做的是在用戶暫停視頻時添加廣告。但似乎我無法通過添加觀察者來獲取MPMoviePlayerPlaybackStateDidChangeNotification。
我做了一些研究,發現這些解決方案:
Media Callbacks with Embedded YouTube Videos on iOS
How to receive NSNotifications from UIWebView embedded YouTube video playback
Get Notification when a video starts or stops in UIWebView
但他們沒有工作,至少對iOS8上。這裏是我從第三個網址的建議使用的代碼:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playbackStateDidChange:)
name:@"MPAVControllerPlaybackStateChangedNotification"
object:nil];
- (void)playbackStateDidChange:(NSNotification *)note
{
NSLog(@"note.name=%@ state=%d", note.name, [[note.userInfo objectForKey:@"MPAVControllerNewStateParameter"] intValue]);
int playbackState = [[note.userInfo objectForKey:@"MPAVControllerNewStateParameter"] intValue];
switch (playbackState) {
case 1: //end
;
break;
case 2: //start
;
break;
default:
break;
}
}
那麼我該怎麼辦?如果我想自己創建MPMoviePlayer,是否意味着我必須實現一個視圖,該視圖看起來像應用程序現在使用的視頻列表html?我認爲這是很多工作要做。那麼如果有什麼方法可以從嵌入在UIWebview中的MPMoviePlayer獲取PlaybackState通知?
任何幫助,將不勝感激。
Thx!我在上面添加了我的代碼,它與第三個url中的代碼相同。暫停我的意思是暫停MoviePlayer,因爲應用程序在視頻播放時調用MoviePlayer。 – Demonedge