我使用故事板對象和此代碼在Objective-C中創建了一個UIWebView。爲什麼我的UIWebView無法顯示Javascript YouTube播放器iFrame?
[videoView setDelegate:self];
NSString *preURL = @"http://example.com/videoscript.php";
NSString *fullURL = [preURL stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
NSURL *url = [NSURL URLWithString:fullURL];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[videoView loadRequest:requestObj];
的WebView中打開此內容
<head>
<script src="http://www.youtube.com/player_api?enablejsapi=1&version=3"></script>
<script language="javascript">
//Load player api asynchronously.
//var tag = document.createElement('script');
//tag.src = "https://www.youtube.com/iframe_api";
// var firstScriptTag = document.getElementsByTagName('script')[0];
//firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
//var done = false;
//var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: '100%',
width: '100%',
videoId: 'JW5meKfy3fY',
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
},
playerVars: {
'controls': '0',
'showinfo': '0',
'showsearch': '0',
'loop': '1',
'embedjsapi': '1',
'qutoplay': '1'
}
});
}
function onPlayerReady(evt) {
evt.target.playVideo();
}
function onPlayerStateChange(evt) {
}
function stopVideo() {
player.stopVideo();
}
</script>
</head>
混亂的部分原因是,罰款在桌面瀏覽器,但在Safari iOS和腳本功能的UIWebView的它不工作的鏈接。我認爲這是缺乏Adobe Flash Player問題,但我認爲使用JavaScript創建一個iFrame與使用實際標籤相同?當我使用標籤時,這確實有效,但該方法對我來說不是一種選擇。所以我的問題是,無論如何要嵌入一個HTML5的YouTube播放器,而不是直接使用Javascript而不是iFrames?