YouTube動画のプレーヤーサイズを変更します。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Language" content="ja" /> <meta http-equiv="Content-Script-Type" content="text/javascript" /> <meta http-equiv="Content-Style-Type" content="text/css" /> <meta http-equiv="imagetoolbar" content="no" /> <title>設置サンプル</title> <link rel="stylesheet" type="text/css" href="/content/lib/global.css" /> <!-- JS --> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script> <script type="text/javascript"> var flashvars = { }; var params = { allowScriptAccess:"always" }; var attributes = { id:"myytplayer" }; swfobject.embedSWF( "http://www.youtube.com/apiplayer?enablejsapi=1&version=3&playerapiid=ytplayer", "ytapiplayer", "560", "340", "8.0.0", /* Flash Player8 以降を指定 */ "/content/lib/swfobject/expressInstall.swf", flashvars, params, attributes ); $(function(){ /* 再生/一時停止 */ $("#btn_play").toggle(function(){ if(ytplayer) ytplayer.playVideo(); },function(){ if(ytplayer) ytplayer.pauseVideo(); }); /* 停止 */ $("#btn_stop").click(function(){ if(ytplayer) ytplayer.stopVideo(); }); $("#resize").change(function(){ var tmp=$(this).val(); var tmp_ary=tmp.split(","); /* 現在のプレーヤーのサイズを変更 */ ytplayer.width = tmp_ary[0]; ytplayer.height = tmp_ary[1]; }); }); /* プレーヤーの準備ができると呼ばれる関数 */ function onYouTubePlayerReady(playerId) { ytplayer = document.getElementById("myytplayer"); ytplayer.cueVideoById("9YEEl52u8XE"); } </script> <!-- CSS --> <style type="text/css"> img { vertical-align:middle; } </style> <link rel="stylesheet" type="text/css" href="/common/css/example.css"></head> <body id='example3' class='example'><div class="ads" style="margin:32px auto;text-align:center;"></div><h1 class='h'><a href='/'>PHP & JavaScript Room</a> :: 設置サンプル</h1> <h3 class='h'>実行結果</h3> <h1>設置サンプル</h1> <h2>FlashのWeb埋め込みライブラリ「SWFObject」を使用したYouTube動画プレーヤーの埋め込み(クロムレスプレーヤー)</h2> <p>YouTube動画のプレーヤーサイズを変更します。</p> <!-- CODE --> <div id="ytapiplayer"> <p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p> </div> <p> <a href="#" id="btn_play"><img src="/content/img/strm/key_play_pause.png" alt="再生/一時停止" /></a> <a href="#" id="btn_stop"><img src="/content/img/strm/key_stop.png" alt="停止" /></a> プレーヤーのサイズ変更: <select id="resize"> <option value="480,295">小</option> <option value="560,340" selected="selected">中</option> <option value="640,385">大</option> </select> </p> <!-- / CODE --> </body> </html>