|
|
<style type="text/css">
#waiDiv { margin:10px auto; padding:8px; width:400px; background:tan; border-radius:10px; box-shadow:2px 2px 4px #000; display:flex; flex-direction:column; position:relative; }
#audDiv { width:100%; display:flex; flex-direction:row; align-items:center; gap:8px; }
#audDiv audio { width:360px; height:30px; }
#audDiv div[id=add1] { margin:6px; background:#eee; text-align:center; width:30px; height:30px; line-height:30px; border-radius:50%; cursor:pointer; }
#mLiDiv { background:#eee; color:#000; min-height:100px; padding:10px; border:1px solid olive; }
#mLiDiv a { cursor:pointer; text-decoration: none; }
#prompt { position:absolute; left:200px; top:50px; width:400px; padding:6px 12px; background:silver; font-size:12px; display:none; box-shadow:1px 1px 1px #666; border-radius:2px; }
#prompt input { outline:none; }
#prompt input[type=text] { margin:4px;padding:4px; width:392px; }
#prompt input[type=button] { border-radius:4px; cursor:pointer; border:1px solid gray; border-radius:3px; box-shadow: 1px 1px 2px #444; }
#prompt input[type=radio] { cursor:pointer; }
</style>
<div id="waiDiv">
<div id="audDiv">
<audio id="myPlayer" controls="controls" loop="loop"></audio>
<div id="add1">+</div>
</div>
<div id="mLiDiv"></div>
<div id="prompt">
<div>添歌&设置</div>
<input type="text" id="mName" placeholder="歌曲名称" /><br />
<input type="text" id="mUrl" placeholder="歌曲地址" /><br /><br />
<div style="text-align:center;">
<input id="subMe" type="button" value="添加" />
<input id="cancelMe" type="button" value="算了" />
<input id="dqxh" type="radio" name="rad" checked="checked" />单曲循环
<input id="lhbf" type="radio" name="rad" />轮回播放
</div>
</div>
</div>
<script language="javascript">
var aud = document.getElementById('myPlayer');
var mLi = document.getElementById('mLiDiv');
var mAdd = document.getElementById('add1');
var prom = document.getElementById('prompt');
var cancelMe = document.getElementById('cancelMe');
var subMe = document.getElementById('subMe');
var dqxh = document.getElementById('dqxh');
var lhbf = document.getElementById('lhbf');
var muAr = [
["https://www.joy127.com/url/88626.mp3","潇洒的走"],
["https://www.joy127.com/url/88624.mp3","古城新韵"],
["https://www.joy127.com/url/88615.mp3","别让我一个人醉"],
["https://www.joy127.com/url/88613.mp3","闹元宵"],
["https://www.joy127.com/url/88618.mp3","迷宫"],
["https://www.joy127.com/url/88617.mp3","爱到底怎么了"],
["https://www.joy127.com/url/88616.mp3","爱的天堂"],
["https://www.joy127.com/url/88623.mp3","未结的果"]
];
var playIdx = 0;
var str = "";
for(i=0; i<muAr.length; i++) { str += (i+1) + ".<a id='list" + i + "' onclick='iPlay(" + i + ")' >" + muAr[1] + "</a><br />";}↓
mLi.innerHTML += str;
function iPlay(idx){
playIdx = idx;
aud.src = muAr[playIdx][0];
aud.play();
nameRed(playIdx);
}
mAdd.onclick = function(){
prom.style.display = "block";
}
cancelMe.onclick = function(){
prom.style.display = "none";
}
subMe.onclick = function(){
let uri = document.getElementById('mUrl');
let name = document.getElementById('mName');
let tnum = muAr.length;
let str1 = uri.value;
let str2 = name.value;
if(str1 !="" && str2 != ""){
muAr[tnum] = [str1, str2];
mLi.innerHTML += (tnum+1) + ".<a id='list" + tnum + "' onclick='iPlay(" + tnum + ")' >" + str2 + "</a><br />";
iPlay(tnum);
uri.value = "";
name.value = "";
}
prom.style.display = "none";
}
function howplay(){
dqxh.checked ? aud.loop = true :(aud.loop = false,playNext(),aud.addEventListener('ended',playNext,false));
prom.style.display = "none";
}
function playNext(){
iPlay(playIdx);
playIdx += 1;
if(playIdx >= muAr.length) playIdx = 0;
}
function nameRed(){
for(i=0;i<muAr.length;i++){
let listId = "list" + i;
document.getElementById(listId).style.color = "black";
}
listId = "list" + playIdx;
document.getElementById(listId).style.color = "red";
}
</script> |
|