我正在將iOS視頻嵌入到iOS應用的UIWebView
中。我在this YouTube blog post上使用「方法2」來嵌入視頻。這很好,除了因爲iOS管理媒體播放器,我無法確定視頻是播放還是播放完成。我不想在視頻播放過程中將視圖與另一個視圖交換,但我沒有看到確定該視圖的好方法。有任何想法嗎?如果有一種方法可以獲得JavaScript回調,那麼這將起作用,或者如果有一種方法可以使用HTML5 <video>
標籤嵌入YouTube視頻,那也可以(我嘗試過並且沒有獲得成功)。iOS上帶有嵌入式YouTube視頻的媒體回調
回答
你可以注入的JavaScript成UIWebView
(見http://iphoneincubator.com/blog/windows-views/how-to-inject-javascript-functions-into-a-uiwebview)......其他有趣的東西關於JavaScript和UIWebView
可以發現here和here。
請嘗試將此與此實驗性的YouTube API一起使用(請參閱http://code.google.com/apis/youtube/iframe_api_reference.html)......這應該能夠讓您得到您想要的。
另一個有用的資源,這個從javascript到你的代碼回調是here。
對於iPhone我使用了一些棘手的方法。當視頻模式視圖控制器被解散時,您可能會收到通知。
-(void) onUIWebViewButtonTouch:(id) sender
{
self.isWatchForNotifications = YES;
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(windowNowVisible:)
name:UIWindowDidBecomeVisibleNotification
object:self.view.window
];
}
- (void)windowNowVisible:(NSNotification *)note
{
if (isWatchForNotifications == YES)
{
//modal viewcontroller was dismissed
}
self.isWatchForNotifications = NO;
}
這可行,但只適用於iPhone全屏播放的視頻。 – 2012-01-18 15:16:50
只需爲MPAVControllerPlaybackStateChangedNotification添加觀察者即可。
[[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;
}
}
探索其他國家,如果你很好奇。另外大家感興趣的一羣其他通知可以註冊即可查看所有:
CFNotificationCenterAddObserver(CFNotificationCenterGetLocalCenter(),
NULL,
noteCallbackFunction,
NULL,
NULL,
CFNotificationSuspensionBehaviorDeliverImmediately);
然後檢查什麼是未來的:
void noteCallbackFunction (CFNotificationCenterRef center,
void *observer,
CFStringRef name,
const void *object,
CFDictionaryRef userInfo)
{
NSLog(@"notification name: %@", name);
NSLog(@"notification info: %@", userInfo);
}
玩得開心!
這種方法可以讓我獲得95%的體驗,但是因爲我同時在屏幕上顯示多個YouTube播放器,所以不會讓我看到哪個視頻開始播放。雖然謝謝! – 2012-01-26 01:30:26
您可以從頭文件解碼更多通知:https://github.com/nst/iOS-Runtime-Headers/blob/master/Frameworks/MediaPlayer.framework/MPAVController.h MPAVControllerItemPlaybackDidEndNotification – 2013-03-08 12:53:40
- 1. iOS中嵌入YouTube視頻
- 2. Swift iOS Youtube嵌入式視頻不玩
- 3. Chromecast在iOS上嵌入YouTube視頻
- 4. 嵌入式視頻youtube
- 5. 嵌入式視頻/ youtube視頻不停
- 6. 流媒體Youtube視頻
- 7. 嵌入式YouTube視頻不上火狐
- 8. 「嵌入式」YouTube視頻無法嵌入
- 9. Youtube如何在Facebook上將其嵌入式視頻回退到iOS上的html5?
- 10. HTTP在Youtube視頻的iOS設備上直播流媒體
- 11. 帶有嵌入式YouTube視頻的Android WebView,全屏按鈕凍結視頻
- 12. 嵌入YouTube視頻
- 13. 嵌入youtube視頻
- 14. 嵌入YouTube視頻?
- 15. 在NativeScript iOS中的嵌入式YouTube視頻在Html/WebView iOS
- 16. 嵌入式視頻在iOS上的Safari
- 17. 播放YouTube視頻嵌入到iOS 6
- 18. 嵌入式懸停在YouTube上的「推薦」視頻嵌入
- 19. 從頁面上的嵌入式YouTube視頻獲取youtube鏈接?
- 20. 更改嵌入式YouTube視頻的CSS
- 21. 嵌入式視頻中的YouTube廣告
- 22. 嵌入的YouTube視頻pregreplace
- 23. 嵌入最近上傳的YouTube視頻
- 24. 播放帶或不帶Flash的嵌入式YouTube視頻,帶或不帶Javascript
- 25. 如何在YouTube視頻嵌入形式獲得從Youtube縮略圖嵌入形式的Youtube視頻
- 26. 嵌入沒有廣告的YouTube視頻
- 27. 在iOS上的Quicktime中啓動嵌入的YouTube視頻
- 28. 適用於YouTube嵌入式視頻的iOS 6.0+自轉
- 29. iOS版的YouTube嵌入式視頻幀問題
- 30. 嵌入式YouTube視頻報廢鏈接
看到這個問題及其答案:http://stackoverflow.com/questions/8518719/how-to-receive-nsnotifications-from-uiwebview-embedded-youtube-video-playback – Till 2012-01-14 21:53:57