Created
July 23, 2012 09:43
-
-
Save darkredz/3162836 to your computer and use it in GitHub Desktop.
Autoplaying Youtube HTML5 Player in UIWebView air native extension
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> | |
| <html><head> | |
| <META http-equiv="Content-Type" content="text/html; charset=UTF-8"/> | |
| <style>body{margin:0px;}</style> | |
| </head> | |
| <body> | |
| <!-- 1. The <div> tag will contain the <iframe> (youtube video player) --> | |
| <div id="player"></div> | |
| <script> | |
| // 2. This code loads the IFrame Player API code asynchronously. | |
| var tag = document.createElement('script'); | |
| tag.src = "http://www.youtube.com/player_api"; | |
| var firstScriptTag = document.getElementsByTagName('script')[0]; | |
| firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); | |
| // 3. This function creates an <iframe> (and YouTube player) after the API code downloads. | |
| var player; | |
| function onYouTubePlayerAPIReady() { | |
| player = new YT.Player('player', { | |
| width: '480', | |
| height: '280', | |
| videoId: 'rynvewVe21Y', | |
| events: { | |
| 'onReady': onPlayerReady} | |
| }); | |
| } | |
| // 4. The API will call this function when the video player is ready. | |
| // using playVideo() is forbidden in Safari mobile browser as well as StageWebView | |
| function onPlayerReady(event) { | |
| event.target.playVideo(); | |
| } | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment