javascript - Youtube video api plays muted, How to unmute it? -
so since i'm complete noob in javascript, tried fixing problem myself keep messing up. here's code : `
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', { height: '100%', width: '100%', playervars: { 'rel':0 , 'autoplay': 1, 'loop':1, 'controls':1, 'start':0, 'autohide':1,'wmode':'opaque' }, videoid: 'k1-travp_xs', events: { 'onready': onplayerready, 'onstatechange': onplayerstatechange} }); } function onplayerready(event) { event.target.mute(); } function onplayerstatechange(event) { if(event.data === 0) { event.target.playvideo(); } }
so yeah. when open webpage, video play muted. :)
actually remove this
function onplayerready(event) { event.target.mute(); }
and
'onready': onplayerready,
unless want when player ready.
edit: if want start video later try changing
event.target.playvideo();
by
settimeout(function() { event.target.playvideo(); }, 5000);
5000 being 5 seconds, change whatever prefer
Comments
Post a Comment