标签:开始 date fun app 列表 lse loaded ade suspend
//使用autoplay属性
var src = "./award.wav";
var body = document.getElementsByTagName("body")[0];
if (body.getElementsByTagName("audio").length <= 0) {
var audio = document.createElement("audio");
audio.setAttribute("id", "awardAudio");
audio.setAttribute("autoplay", "autoplay");
audio.setAttribute("src", src);
body.appendChild(audio);
setTimeout(function() {
body.removeChild(audio);
}, 2300);
}
// 监听加载事件执行play方法
var src = "./award.wav";
var body = document.getElementsByTagName("body")[0];
if (body.getElementsByTagName("audio").length <= 0) {
var audio = document.createElement("audio");
audio.setAttribute("id", "awardAudio");
audio.setAttribute("src", src);
body.appendChild(audio);
audio.addEventListener(
"canplaythrough",
function() {
audio.play();
setTimeout(function() {
body.removeChild(audio);
}, audio.duration * 1000 + 100);
},
false
);
}
duration 在 autoplay 下回失效,返回 NaN
HTML 5 视频/音频参考手册
HTML5 声音引擎 Howler.js
MDN audio
基于 react 的 audio 组件
HTML5 Audio 的兼容性问题和优化
html5 audio 音频播放全解析
音频 API => AudioContext
标签:开始 date fun app 列表 lse loaded ade suspend
原文地址:https://www.cnblogs.com/mybilibili/p/10376528.html