Youtubeã®ãã¬ã¼ã¤ã¼ã¯JavaScriptã§å¶å¾¡ã§ããã¨å ¬å¼ãªãã¡ã¬ã³ã¹ã§è¦ã¤ããã®ã§ã¡ãã£ã¨è©¦ãã¦ã¿ã¾ããã
YouTube JavaScript Player API ãªãã¡ã¬ã³ã¹ - YouTube ã® API ã¨ãã¼ã« - Google Code
http://code.google.com/intl/ja/apis/youtube/js_api_reference.html
å ¬å¼ãµã¤ãã®ãã¬ã¤ã¤ã¼ãå¶å¾¡
ãªãã¡ã¬ã³ã¹ãåèã«è©¦è¡é¯èª¤ããçµæãYoutubeã®å ¬å¼ãµã¤ãã§ã¯(2009/03/03ç¾å¨)以ä¸ã®Javascriptã§åä½å¯è½ãªæ§ã§ãã
公式サイトã§åç»ãåçããå¾ã以ä¸ã®ã¹ã¯ãªãããã¢ãã¬ã¹ãã¼ã«å ¥åãã¦ã¿ã¦ä¸ããã
ä¸æåæ¢
javascript:(function(){var player = _gel("movie_player");player.pauseVideo();})();
åç
javascript:(function(){var player = _gel("movie_player");player.playVideo();})();
åæ¢(åéãåºæ¥ãªãæ§ãªã®ã§ä¸æåæ¢ã使ç¨ããæ¹ãè¯ãã§ããã)
javascript:(function(){var player = _gel("movie_player");player.stopVideo();})();
å ¬å¼ãµã¤ã以å¤ã®ãµã¤ãã«åãè¾¼ã¾ãããã¬ã¤ã¤ã¼ãå¶å¾¡
ä¾ã¨ãã¦ä»¥åå ¬éããこちらã®åç»ãåãè¾¼ã¿ããã®ãã¬ã¤ã¤ã¼ãå¶å¾¡ããããã°ã©ã ã®ä½ææ¹æ³ã解説ãã¾ãã
1. 対象ã®åç»ãYoutubeã§éãã
2. ç»é¢å³å´ã«ãããåè¾¼ã¿ãããåãè¾¼ã¿ã³ã¼ããã³ãã¼ã
3. ã³ãã¼ããã³ã¼ããã¨ãã£ã¿ãªã©ã«å¼µãä»ããå
é ã®ä»¥ä¸ã®é¨åã«IDã追å ã
<object width="
â
<object id="ytplayer" width="
4. ç¶ã㦠src= ã®é¨åãè¦ã¤ããURLã®æå¾ã« enablejsapi=1 ã追å (ããã«ãããJavaScriptã§å¶å¾¡å¯è½ã«ãªãã¾ã)ã
<embed src="http://www.youtube.com/v/Z7yh_mwAhYc&hl=ja&fs=1"
â
<embed src="http://www.youtube.com/v/Z7yh_mwAhYc&hl=ja&fs=1&enablejsapi=1"
5. å¶å¾¡é¢é£ã®ããã°ã©ã ã追å ã
var obj = document.getElementById("ytplayer"); var player = obj.getElementsByTagName("embed")[0]; function play() { if (player) { player.playVideo(); } }
ãããã°ã©ã ã®è§£èª¬ã
3. ã§æå®ããIDãå
ã«è©²å½ã®objectã¿ã°ãåå¾ã
var obj = document.getElementById("ytplayer");
ãã®objectã¿ã°ã®ä¸ã® embed ã¿ã°ãåå¾ãã¾ãã
var player = obj.getElementsByTagName("embed")[0];
ããã«ããå ¬å¼ãªãã¡ã¬ã³ã¹ã¨åæ§ã« player ãåå¾ãå®äºãã¾ãããå¾ã¯ãªãã¡ã¬ã³ã¹ãåç §ããªããå®è¡ãããå¦çãè¨è¿°ãã¾ãã
function play() { if (player) { player.playVideo(); } }
主ãªããã°ã©ã é¨åã¯ä»¥ä¸ã®æ§ã«ãªãã¾ãã
<object id="ytplayer" width="425" height="344"><param name="movie" value="http://www.youtube.com/v/Z7yh_mwAhYc&hl=ja&fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/Z7yh_mwAhYc&hl=ja&fs=1&enablejsapi=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object> <script type="text/javascript"> var obj = document.getElementById("ytplayer"); // èªåã§è¿½å ããIDã§è©²å½ã®objectã¿ã°ã®ãªãã¸ã§ã¯ããåå¾ var player = obj.getElementsByTagName("embed")[0]; // objectã¿ã°å ã®embedã¿ã°ãåå¾ function play() { if (player) { player.playVideo(); } } function pause() { if (player) { player.pauseVideo(); } } </script> <input type="button" value="Play" onclick="play();"> <input type="button" value="Pause" onclick="pause();">
å ¨ããã°ã©ã ã®ç¢ºèªãåä½ç¢ºèªã¯こちらã§ç¢ºèªã§ãã¾ãã
â»å ¬å¼ãªãã¡ã¬ã³ã¹ã§ã¯ãJavaScript API ã§ã¢ã¯ã»ã¹ãããã¬ã¼ã¤ã¼ã®åãè¾¼ã¿ã«ã¯ãSWFObject ã使ç¨ãããã¨ããå§ããã¾ãããã¨ããã¾ããã SWFObject ã§ã¯Mac+Firefox3.0ã§ãã¾ãåçãããªãã£ãããã«ä»åã®ãããªæ¹æ³ã§ä½æãã¾ããã