console
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>音频测试</title>
<script src="https://cdn.bootcdn.net/ajax/libs/jszip/3.6.0/jszip.min.js"></script>
</head>
<body>
<button id="btnPlay" style="font-size: larger;color:chocolate">Play</button>
<audio id="myAudio" src="https://oss.qwjiaoyu.com/upload/IM/qq.mp3" autoplay> your browser does not support the audio tag</audio>
<div id="input-upload-file">
<span>upload</span>
<input type="file" class="upload" id="fileUp" name="fileUpload">
</div>
<pre id="messages"></pre>
<script>
window.URL = window.URL || window.webkitURL;
window.onload = function () {
var isPlay = false;
var playInterval;
var audioElment = document.getElementById('myAudio');
var btnButton = document.getElementById('btnPlay');
btnButton.addEventListener("click", function () {
if (isPlay && playInterval) {
clearInterval(playInterval);
isPlay = false;
btnButton.innerHTML = "Play";
return;
}
audioElment.play();
playInterval = setInterval(function () {
console.log("play mp3");
audioElment.play();
}, 4000);
isPlay = true;
btnButton.innerHTML = "Pause";
});
var myVideos = [];
var fileUploadEl = document.getElementById('fileUp');
var messageEl = document.getElementById('messages');
fileUploadEl.onchange = function(){
var files = this.files;
myVideos.push(files[0]);
var video = document.createElement('video');
video.preload = 'metadata';
video.onloadedmetadata = function() {
window.URL.revokeObjectURL(video.src);
var duration = video.duration;
myVideos[myVideos.length - 1].duration = duration;
showMessage();
}
video.src = URL.createObjectURL(files[0]);
};
function showMessage() {
messageEl.textContent = "";
for (var i = 0; i < myVideos.length; i++) {
messageEl.textContent += myVideos[i].name + " duration: " + myVideos[i].duration + '\n';
}
}
};
</script>
</body>
</html>