Youtube javascript API and Android application in webview -
i use youtube javascript api autoplay youtube video in android application. (version 2.2 , later) in application load html in webview. use same code in ios application. ios work. when load video, video playing automatically.
with android when load html, code loadded, video start launch it's never read.
when desable autoplay , user click on video, work ! , have enable : android:hardwareaccelerated="true"
<!doctype html> <html> <body> <div id="player"></div> <script> 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 player; function onyoutubeiframeapiready() { player = new yt.player('player', { height: '150', width: '300', videoid: 'ew5w684byfw', events: { 'onready': onplayerready, 'onstatechange': onplayerstatechange } }); } function onplayerready(event) { event.target.playvideo(); } var done = false; function onplayerstatechange(event) { if (event.data == yt.playerstate.playing && !done) { // settimeout(stopvideo, 6000); done = true; } } function stopvideo() { player.stopvideo(); } </script> </body>
can me ?
edit : work on android 2.2 galaxy s2 not on galaxy s3 (android4.1)!
Comments
Post a Comment