<!DOCTYPE html>
<html>
<meta charset="utf-8" />
<head>
<link rel="stylesheet" href="index.css" />
<script type="text/javascript" src="https://libs.baidu.com/jquery/1.4.2/jquery.min.js"></script>
</head>
<body>
<div id="card">
<h1>带有AB复读功能的播放器</h1>
<div id="audioContainer">
<audio id="myaudio" src="" controls="controls">您的浏览器不支持 audio 标签。</audio>
<!-- <button onclick="autoPlay()" style="BACKGROUND-IMAGE: url(next.jpg);BACKGROUND-REPEAT: no-repeat;" /> -->
<!-- <input type="image" src="next.svg" onclick="nextPlay()" name="下一曲" /> -->
<!-- <img src="next.svg" alt="" onclick="nextPlay()" /> -->
<img
src="data:image/svg+xml;base64,PHN2ZyB0PSIxNzE2NTI3MzUxNzcyIiBjbGFzcz0iaWNvbiIgdmlld0JveD0iMCAwIDEwMjQgMTAyNCIgdmVyc2lvbj0iMS4xIg0KICAgIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgcC1pZD0iMTQ3MiIgd2lkdGg9IjQwIiBoZWlnaHQ9IjQwIj4NCiAgICA8cGF0aCBkPSJNMjAxLjM0NCA4ODEuMDg4Yy0yOC4yMjQgMjEuMDU2LTUxLjI2NCA5LjQ3Mi01MS4yNjQtMjUuNjY0VjE2OC43MDRjMC0zNS4yIDIzLjA0LTQ2Ljc4NCA1MS4yNjQtMjUuNzI4bDQ0Mi45NDQgMzMwLjc1MmMyOC4xNiAyMS4wNTYgMjguMTYgNTUuNTUyIDAgNzYuNjA4bC00NDIuOTQ0IDMzMC43NTJ6TTg3My45ODQgODU1LjM2YzAgMzUuMi0yMi4wOCA2NC00OS4wMjQgNjQtMjcuMDA4IDAtNDkuMDg4LTI4LjgtNDkuMDg4LTY0VjE2OC43MDRjMC0zNS4yIDIyLjA4LTY0IDQ5LjA4OC02NCAyNi45NDQgMCA0OS4wMjQgMjguOCA0OS4wMjQgNjR2Njg2LjY1NnoiIGZpbGw9IiMzMzMzMzMiIHAtaWQ9IjE0NzMiPjwvcGF0aD4NCjwvc3ZnPg==""
alt="" onclick="nextPlay()" />
<input type="button" id="select" value="选择歌曲文件夹" onclick="selectMP3()" />
<button id="loop">单曲循环</button>
</div>
<input type="file" id="files" name="files[]" multiple webkitdirectory style="display: none" accept="audio/mpeg" />
<p><span>播放时间:</span><span id="currentTime"></span></p>
<p>
<span>播放速度:</span>
<select id="playRate" onchange="rate()">
<option value="2">2</option>
<option value="1.5">1.5</option>
<option value="1" selected="selected">1</option>
<option value="0.5">0.5</option>
</select>
</p>
<input type="button" value="开始时间" onclick="startTimefun()" /><span id="start"></span>
<input type="button" value="结束时间" onclick="endTimefun()" /><span id="end"></span>
<input type="button" value="清除复读" onclick="reset()" />
<div>
<ul id="songlist"></ul>
</div>
</div>
<div class="anim" id="cover">
<img src="" alt="" />
</div>
<script language="javascript" type="text/javascript">
var input = document.getElementById("files");
var songlist = document.getElementById("songlist");
var song = songlist.innerHTML;
var myAuto = document.getElementById("myaudio");
myAuto.volume = 0.5; //初始默认音量
var loopbtn = document.querySelector("#loop");
// AB复读代码Start
var startTime = "";
var endTime = "";
//速度调节
function rate() {
var s = document.getElementById("playRate");
myAuto.playbackRate = s[s.selectedIndex].value;
}
function startTimefun() {
startTime = myAuto.currentTime;
$("#start").text(startTime);
}
function endTimefun() {
endTime = myAuto.currentTime;
$("#end").text(endTime);
}
function reset() {
startTime = "";
endTime = "";
$("#start").text(startTime);
$("#end").text(endTime);
}
myAuto.ontimeupdate = function () {
$("#playbackRate").text(myAuto.playbackRate); //显示播放时间
$("#currentTime").text(myAuto.currentTime); //显示播放速度
if (startTime != "" && endTime != "") {
if (parseInt(myAuto.currentTime) >= endTime) {
myAuto.currentTime = startTime;
}
}
};
// AB复读代码End
input.onchange = function (e) {
var files = e.target.files; // FileList
var count = 0;
for (var i = 0, f; (f = files[i]); ++i) {
//file have .name
var path = f.name || f.webkitRelativePath;
if (/\.(mp3|wav|aac|flac|ogg|m4a)$/i.test(path)) {
var url;
// if (window.createObjectURL) {
// url = window.createObjectURL(files[i]);
// } else if (window.createBlobURL) {
// url = window.createBlobURL(files[i]);
// } else if (window.URL && window.URL.createObjectURL) {
// url = window.URL.createObjectURL(files[i]);
// } else if (window.webkitURL && window.webkitURL.createObjectURL) {
// url = window.webkitURL.createObjectURL(files[i]);
// }
url = window.URL.createObjectURL(files[i]);
if (count % 2 === 0) {
song += '<li class="song odd" onclick="changeSrc(event)" ><input type="hidden" value="' + url + '"/>' + path + "</li>";
} else {
song += '<li class="song even" onclick="changeSrc(event)" ><input type="hidden" value="' + url + '"/>' + path + "</li>";
}
count++;
} else {
if (path === "folder.jpg") {
var url = window.URL.createObjectURL(files[i]);
const img = document.querySelector("#cover img");
img.src = url;
console.log(path, files[i]);
}
}
}
songlist.innerHTML = song;
};
myAuto.addEventListener("ended", function () {
nextPlay();
});
function nextPlay() {
var next = $(".cur").next();
next.addClass("cur").siblings().removeClass("cur");
var cur = document.getElementsByClassName("cur");
myAuto.src = cur[0].firstChild.value;
myAuto.play();
}
function selectMP3() {
console.log(song);
input.click();
}
function changeSrc(event) {
event = event ? event : window.event;
var obj = event.srcElement ? event.srcElement : event.target;
$(obj).addClass("cur").siblings().removeClass("cur");
myAuto.src = obj.firstChild.value;
myAuto.play();
}
loopbtn.addEventListener("click", function () {
if (myAuto.hasAttribute("loop")) {
myAuto.removeAttribute("loop");
loopbtn.classList.remove("loop");
} else {
myAuto.setAttribute("loop", "");
loopbtn.classList.add("loop");
}
});
myAuto.addEventListener("play", function () {
const img = document.querySelector("#cover");
// img.classList.add("anim");
img.style.animationPlayState = 'running';
console.log("The audio started to play");
});
myAuto.addEventListener("pause", function () {
const img = document.querySelector("#cover");
img.style.animationPlayState = 'paused';
// img.classList.remove("anim");
});
</script>
</body>
</html>
![avatar](https://profile-avatar.csdnimg.cn/ba90dfbe589748b6b53784024250420c_daban2008.jpg!1)
daban2008
- 粉丝: 78
- 资源: 5
最新资源
- java common-lang-commons-lang.jar
- JPEGsnoop-v1-8-0a.zip
- 一款基于.NET Core Web + Bootstrap的企业级快速后台开发框架 内置模块如:用户管理、部门管理、菜单管理、
- 程序名称:悬架设计计算程序 开发平台:基于matlab平台 计算内容:悬架偏频刚度挠度;螺旋弹簧,多片簧,少片簧,稳定杆,减震器
- android studio 配套资源 gradle8.7all
- LabVIEW串口RS485 Modbus通讯三菱PLC FX5U PLC,官方协议,报文读取,安全稳定 通讯配置,辅助测试
- jacob-1.18-1.19文件转MP3语音工具包
- EmlogPro访问网站时需要密码验证插件
- [Java毕业设计]基于springboot vue的毕业生信息招聘平台的设计与实现-论文-源码
- 基于小波和神经网络的均衡算法,matlab仿真程序 (1)中信道要求多径衰弱信道 (2)中信道传统电话信道模型,(2)中和神
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)