JS网页音乐播放器代码,上一首,下一首,连播

<script>
/*************************************************************
LovelyLife Player V1.0
Edited By LovelyLife
At 2006-09-16
All rights reservered
Code Start
Modify by http://www.tt419.cn/ 
*************************************************************/
var playid = "LovelyLifePlayer"
var status = "status"
var curId,arrPL,selected
var isStop,isLoop
arrPL = new Array()    //播放器列表
cur = 0
curId = 0
isStop = false
selected = 0
isLoop = true
function songObj(Id,url, name){
this.Id   = Id
this.url  = url
this.name = name
}
function playAndpauseIt(){
if(document.getElementById(status).innerText == '暂停'){
document.getElementById(playid).controls.pause()
document.getElementById(status).innerHTML ='播放'
}
else{ document.getElementById(status).innerText = '暂停'
document.getElementById(playid).controls.play()}
}
function stopIt(){
isStop = true
document.getElementById(status).innerHTML ='播放'
document.getElementById(playid).controls.stop()
}
function showTimer(){
var cp=document.getElementById(playid).controls.currentPosition
var cps=document.getElementById(playid).controls.currentPositionString
var dur=document.getElementById(playid).currentMedia.duration;
var durs=document.getElementById(playid).currentMedia.durationString;
var s = document.getElementById(playid).playState
var o = document.getElementById(playid).openState
if( s==2 || s==3)
document.getElementById('pos').innerText = " " + cps + "/" + durs + " "
else
document.getElementById('pos').innerText = " 00:00/" + durs + " "
if( s == 1 ){
if(isLoop && (curId > (arrPL.length - 1))){
curId = 0
return 0
}
clearIt()
if(curId<0 || curId>arrPL.length){
alert("当前没有歌曲!,请查看播放列表!")
return false
}
nxtPlay()
}
if( s == 10 && arrPL.length >0 )
nxtPlay()
}
function nxtPlay(){
isStop = true
if(curId > arrPL.length - 1){
document.getElementById("songName").innerText = "没有歌曲了,请选择上一曲!"
document.getElementById(playid).URL = "NULL"
return false
}
curId++
clearIt()
setIt(curId)
PlayIt(curId)
}
function prePlay(){
isStop = true
if(curId<0){
document.getElementById("songName").innerText = "没有歌曲了,请选择下一曲!"
document.getElementById(playid).URL = "NULL"
return false
}
curId--
clearIt()
setIt(curId)
PlayIt(curId)
}
function PlayIt(cid){
if(curId<0 || curId>arrPL.length -1){
document.getElementById("songName").innerText  = "当前没有歌曲!,请查看播放列表!"
return false
}
 url = arrPL[cid].url;
 
curId = cid
if(url == "None"){
document.getElementById("songName").innerText = "加载歌曲未找到!播放下一曲!"
nxtPlay()
return false
}
document.getElementById(playid).URL = url
document.getElementById("songName").innerText = arrPL[cid].name
}
function clearIt(){
if((arrPL.length - 1 <0) || selected < 0 || selected > arrPL.length){
 
return false
}
 
}
function setIt(tid){
if(tid<0 || tid>arrPL.length-1){
document.getElementById("songName").innerText  = "当前没有歌曲!,请查看播放列表!"
return false
}
 
}
function InitPlay(songName,url,auto){
 
var strTemp = "<object classid=\"CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6\""
strTemp += " type=\"application/x-oleobject\" width=\"0\" height=\"0\" id=" + playid
strTemp += " style=\"position:relative; left:0px; top:0px; width:0px; height:0px;\">\n"
strTemp += "  <param name=\"autoStart\" value=\""+auto+"\">\n"
strTemp += "  <param name=\"balance\" value=\"0\">\n"
strTemp += "  <param name=\"currentPosition\" value=\"0\">\n"
strTemp += "  <param name=\"currentMarker\" value=\"0\">\n"
strTemp += "  <param name=\"enableContextMenu\" value=\"0\">\n"
strTemp += "  <param name=\"enableErrorDialogs\" value=\"0\">\n"
strTemp += "  <param name=\"enabled\" value=\"-1\">\n"
strTemp += "  <param name=\"fullScreen\" value=\"0\">\n"
strTemp += "  <param name=\"invokeURLs\" value=\"0\">\n"
strTemp += "  <param name=\"mute\" value=\"0\">\n"
strTemp += "  <param name=\"playCount\" value=\"1\">\n"
strTemp += "  <param name=\"rate\" value=\"1\">\n"
strTemp += "  <param name=\"uiMode\" value=\"none\">\n"
strTemp += "  <param name=\"volume\" value=\"100\">\n"
strTemp += "  <param name=\"URL\" value=\"" + url + "\">\n"
strTemp += "</object>\n<font class=HighLight style=\"background-color: #EEE;padding: 8px;height:30px;width:100%\">"
strTemp += "<b>点播的歌曲: <marquee width=30% speed=3><font color=red id=songName>" + songName + "</font></marquee>"
strTemp += "   [<font id=pos></font>]"
strTemp += "  [<font οnclick=playAndpauseIt() style='cursor:hand;' id=" + status + ">播放</font>]"
strTemp += "[<font οnclick=stopIt() style='cursor:hand;'>停止</font>]"
if((arrPL.length - 2) >= 0){
strTemp += "[<font οnclick=prePlay() style='cursor:hand;'>上曲</font>]"
strTemp += "[<font οnclick=nxtPlay() style='cursor:hand;'>下曲</font>]"
}
strTemp += " </b>"
document.getElementById('player').innerHTML = strTemp
temptimer=setInterval('showTimer()',1000);
}
function playX(cur){
PlayIt(cur)
clearIt()
setIt(cur)
curId = cur
selected = cur
}
function MakeList(Id,Url,Name){
arrPL[cur] = new songObj(Id,Url, Name)
cur++
}
function loopIt(){
if(isLoop){
document.getElementById('sloop').innerText = "不循环"
isLoop = false
}else{
document.getElementById('sloop').innerText = "循环播放"
isLoop = true
}
}
/* Code End */
window.attachEvent('onload', function(){
    InitPlay("女人如烟[词曲:穆真 演唱:魏佳艺]","http://happy369.com/yy/nrry.mp3", 1);
    playAndpauseIt();
    })
</script>
<div id=player style="width:70%"></div>
<script>
MakeList(1,"http://happy369.com/yy/nrry.mp3","111");
MakeList(2,"http://www.gxyx.net/sourcefile/0/0/2/2958.wma","222");
MakeList(3,"http://hz.98777.com/rm0402/q/258.rm","333");
MakeList(4,"http://www.gxyx.net/sourcefile/0/0/2/2958.wma","4444");
</script>
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
javascript 播放器 控制 发表:不详 阅读: 37 次 关键字:不详 字体:[大 中 小] 详细参数可查询MSDN http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmplay/mmp_sdk/settingsobject.asp <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <link href="style/style.css" rel="stylesheet" type="text/css"> <script language="JavaScript"> var state; //初始化 function playerinit() { player.url="mp3.m3u"; player.settings.autoStart = false ; } //播放 function play() { if (player.controls.isavailable('play')) { player.controls.play(); state=setInterval("updatetime()",1000); playerinfo.innerHTML = "播放"; } } //暂停 function pause() { if (player.controls.isavailable('pause')) { player.controls.pause(); clearInterval(state); playerinfo.innerHTML = "暂停"; } } //停止 function stop() { if (player.controls.isavailable('stop')) { player.controls.stop(); clearInterval(state); playerinfo.innerHTML = "停止"; } } //前首 function previous() { if (player.controls.isavailable( 'previous' )) { player.controls.previous(); playerinfo.innerHTML = "前一首"; } } //后首 function next() { if (player.controls.isavailable( 'next' )) { player.controls.next(); playerinfo.innerHTML = "下一首"; } } //? function step() { if (player.controls.isavailable( 'step' )) player.controls.step( 1 ); } //音量- function voldown() { if ( player.settings.volume < 5 ) { player.settings.volume = 0; playerinfo.innerHTML = "0"; } else { player.settings.volume -= 5; playerinfo.innerHTML = player.settings.volume; } } //音量+ function volup() { if ( player.settings.volume > 95 ) { player.settings.volume = 100; playerinfo.innerHTML = "100"; } else { player.settings.volume += 5; playerinfo.innerHTML = player.settings.volume; } } //静音 function mute() { player.settings.mute = !player.settings.mute; } //声道 function balance() { switch (player.settings.balance) { case 0: player.settings.balance = 100; playerinfo.innerHTML = '左声道'; break; case 100: player.settings.balance = -100; playerinfo.innerHTML = '右声道'; break; case -100: player.settings.balance = 0; playerinfo.innerHTML = '全声道'; break; default : player.settings.balance = 0; playerinfo.innerHTML = '全声道'; break; } } //更新时间 function updatetime() { playerinfo.innerHTML = player.controls.currentPositionString + " | " + player.currentMedia.durationString; } </script> </head> <body onload="playerinit();"> <table width="300"> <tr> <td><object id="player" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" type="application/x-oleobject" width="300" height="60"> <param name="autoStart" value="false"> <param name="balance" value="0"> <param name="currentPosition" value="0"> <param name="currentMarker" value="0"> <param name="enableContextMenu" value="true"> <param name="enableErrorDialogs" value="false"> <param name="enabled" value="true"> <param name="fullScreen" value="false"> <param name="invokeURLs" value="false"> <param name="mute" value="true"> <param name="playCount" value="1"> <param name="rate" value="1"> <param name="uiMode" value="none"> <param name="volume" value="100"> </object></td> </tr> <tr> <td><span id="playerinfo"></span></td> </tr> <tr> <td> <div align="center"> <input type="button" onmouseover=this.className="but12"; onmouseout=this.className="but11"; name="previous" title="上一首" onclick="previous();"> <input type="button" onmouseover=this.className="but22"; onmouseout=this.className="but21"; name="play" title="播放" onclick="play();"> <input type="button" onmouseover=this.className="but32"; onmouseout=this.className="but31"; name="pause" title="暂停" onclick="pause();"> <input type="button" onmouseover=this.className="but42"; onmouseout=this.className="but41"; name="stop" title="停止" onclick="stop();"> <input type="button" onmouseover=this.className="but52"; onmouseout=this.className="but51"; name="next" title="下一首" onclick="next();"> <input type="button" onmouseover=this.className="but62"; onmouseout=this.className="but61"; name="voldown" title="音量-" onclick="voldown();"> <input type="button" onmouseover=this.className="but62"; onmouseout=this.className="but61"; name="volup" title="音量+" onclick="volup();"> <input type="button" onmouseover=this.className="but62"; onmouseout=this.className="but61"; name="mute" title="静音" onclick="mute();"> <input type="button" onmouseover=this.className="but62"; onmouseout=this.className="but61"; name="balance" title="声道" onclick="balance();"> </div> </td> </tr> </table> <script language = "JavaScript" for = player event = playstatechange(newstate)> switch (newstate){ case 1: playerinfo.innerHTML = "停止"; break; case 2: playerinfo.innerHTML = "暂停"; break; case 3: playerinfo.innerHTML = "正在播放"; break; case 4: playerinfo.innerHTML = "4"; break; case 5: playerinfo.innerHTML = "5"; break; case 6: playerinfo.innerHTML = "正在缓冲..."; break; case 7: playerinfo.innerHTML = "7"; break; case 8: playerinfo.innerHTML = "8"; break; case 9: playerinfo.innerHTML = "正在连接..."; break; case 10: playerinfo.innerHTML = "准备就绪。欢迎光临<a href='http://mp3.asp2004.net'>http://mp3.asp2004.net</a>"; break; case 11: playerinfo.innerHTML = "11"; break; default: playerinfo.innerHTML = ""; } </script> </body> </html>

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值