以前は(iOS 6で)、YouTubeプレーヤーに幅と高さを「伝える」ことができ、問題はありませんでした。
このコードは以前は iOS 6 で機能していましたが、iOS 7 ではまったく機能しなくなりました。
しかし今では、画面自体よりも高さと幅にはるかに (3 倍) 高い値を入力する必要がありますが、デバイスのサイズが異なるため、もちろんそれは解決策ではありません。
これは、ボタンが押されたときに実行されるコードです
NSString *player = @"<!DOCTYPE html>
<html>
<head><style>body{margin:0px 0px 0px 0px;}</style></head>
<body>
<div id=\"player\"></div>
<script>
var tag = document.createElement('script');
tag.src = \"http://www.youtube.com/player_api\";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player;
function onYouTubePlayerAPIReady()
{
player = new YT.Player('player', { width:'%0.0fpx', height:'%0.0fpx', videoId:'%@',
playerVars: {playsinline : 1, rel:0, showinfo:0}, events: { 'onReady': onPlayerReady, } });
}
function onPlayerReady(event) { event.target.playVideo();
}
</script>
</body>
</html>"; //End of player creation string
//Then I create the html with the size of the screen
NSString *html = [NSString stringWithFormat:player,[[UIScreen mainScreen] bounds].size.width , [[UIScreen mainScreen] bounds].size.height , @"5bCRDI1BESc"];
//And then I load the html into the webview
[self.webView loadHTMLString:html baseURL:[[NSBundle mainBundle] resourceURL]];
ここから生成される HTML は次のとおりです。
<html><head><style>body{margin:0px 0px 0px 0px;}</style></head>
<body>
<iframe id="player" frameborder="0" allowfullscreen="1" title="YouTube video player" width="320px" height="480px" src="http://www.youtube.com/embed/5bCRDI1BESc?playsinline=1&rel=0&showinfo=0&enablejsapi=1"></iframe> <script src="http://s.ytimg.com/yts/jsbin/www-widgetapi-vflvlw_TO.js" async=""></script><script src="http://www.youtube.com/player_api"></script><script> var tag = document.createElement('script'); tag.src = "http://www.youtube.com/player_api"; var firstScriptTag = document.getElementsByTagName('script')[0]; firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player; function onYouTubePlayerAPIReady() {
player = new YT.Player('player', { width:'320px', height:'480px',
videoId:'5bCRDI1BESc',
playerVars: {playsinline : 1, rel:0, showinfo:0},
events: { 'onReady': onPlayerReady, } });
}
function onPlayerReady(event) { event.target.playVideo(); } </script> </body></html>
しかし結果は、プレイヤーがホワイトスペース (webview) に入力する iOS 6 とは異なります。ここに写真があります
次に、HTML に入る幅と高さを 640px と 960px に(画面サイズ!) 2 倍にすると!?
iOS 7 で YouTube API または Safari ブラウザに何が起こったのか知っている人はいますか?