如何使用javascript来自动播放html5音频标签 [英] How to use a javascript to autoplay a html5 audio tag

查看:135
本文介绍了如何使用javascript来自动播放html5音频标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 <$ c 

$ c>< script type =text / javascriptsrc =http://www.ussc.gov/include/js/konami.js>< / script>
< script type =text / javascript>
var success = function(){
document.body.style.backgroundImage =url(http://3.bp.blogspot.com/-vKs53Qq5mBI/T9vCsCb-irI/AAAAAAAAB8U/CZsS0iY5RjY/s1600 /14685_1_other_wallpapers_anonymous.jpg);
document.body.style.backgroundSize =100%;
if(window.KICKASSGAME){window.KICKASSGAME.menuManager.menu.messageTypeChangeShip('242,0');
window.KICKASSGAME.menuManager.destroy()} else {
alert(AntiSec CAEK模式激活...销毁系统!控件:向上,向下,向左,向右,空间发射。 );
var KICKASSVERSION ='2.0';
var s = document.createElement('script');
s.type ='text / javascript'; document.body.appendChild(s);
s.src ='// hi.kickassapp.com/kickass.js';
void(0);}
}

var konami = new Konami(success);

< / script>


解决方案

play

  var audioElement = document.createElement('audio'); 
audioElement.setAttribute('src','YourSong.ogg');
audioElement.load()
audioElement.addEventListener(load,function(){
audioElement.play();
},true);


I saw this deface from anonymous, so I want to add a hidden chiptune song when playing the game, but got kinda lost.

<script type="text/javascript" src="http://www.ussc.gov/include/js/konami.js"></script>
<script type="text/javascript">
  var success = function() {
                document.body.style.backgroundImage = "url(http://3.bp.blogspot.com/-vKs53Qq5mBI/T9vCsCb-irI/AAAAAAAAB8U/CZsS0iY5RjY/s1600/14685_1_other_wallpapers_anonymous.jpg)";
                document.body.style.backgroundSize = "100%";
                if(window.KICKASSGAME){window.KICKASSGAME.menuManager.menu.messageTypeChangeShip('242,0');
                                       window.KICKASSGAME.menuManager.destroy()}else{
    alert("AntiSec CAEK-mode activated... Destroy the system! Controls: up, down, left, right, space to fire.");
                var KICKASSVERSION='2.0';
                var s = document.createElement('script');
                s.type='text/javascript';document.body.appendChild(s);
                s.src='//hi.kickassapp.com/kickass.js';
                void(0);}
  }

  var konami = new Konami(success);

</script> 

解决方案

play is the method you are looking for

var audioElement = document.createElement('audio');
audioElement.setAttribute('src', 'YourSong.ogg');
audioElement.load()
audioElement.addEventListener("load", function() { 
  audioElement.play(); 
}, true);

这篇关于如何使用javascript来自动播放html5音频标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆