This article describes how to use JavaScript to share a music player instance with a playlist, including a prompt function for a song that is not to be played after the playlist is played, you can refer to the player implementation with the most basic code to add playlist. You can use MakeList to play multiple videos. If you need playlist, you can use it directly:
Untitled PageScript/*********************************** * ********************** LovelyLife Player V1.0Edited By LovelyLifeAt 2006-09-16All rights reserveredCode StartModify http://www.tt419.cn/ **************************************** * *******************/Var playid = "LovelyLifePlayer" var status = "status" var curId, arrPL, selectedvar isStop, isLooparrPL = new Array () // player list cur = 0 curId = 0 isStop = falseselected = 0 isLoop = truefunction songObj (Id, url, name) {this. id = Idthis. url = urlthis. name = name} function playAndpauseIt () {if (document. getElementById (status ). innerText = 'hangzhou') {document. g EtElementById (playid ). controls. pause () document. getElementById (status ). innerHTML = 'player'} else {document. getElementById (status ). innerText = 'hangzhou' document. getElementById (playid ). controls. play ()} function stopIt () {isStop = truedocument. getElementById (status ). innerHTML = 'play' document. getElementById (playid ). controls. stop ()} function showTimer () {var cp = document. getElementById (playid ). controls. currentPositionv Ar cps = document. getElementById (playid ). controls. currentPositionStringvar dur = document. getElementById (playid ). currentMedia. duration; var durs = document. getElementById (playid ). currentMedia. durationString; var s = document. getElementById (playid ). playStatevar o = document. getElementById (playid ). openStateif (s = 2 | s = 3) document. getElementById ('pos '). innerText = "" + cps + "/" + durs + "" elsedocument. g EtElementById ('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 ("no songs currently !, View the playlist! ") Return false} nxtPlay ()} if (s = 10 & arrPL. length> 0) nxtPlay ()} function nxtPlay () {isStop = trueif (curId> arrPL. length-1) {document. getElementById ("songName "). innerText = "no more songs. Please select the last song! "Document. getElementById (playid ). URL = "NULL" return false} curId ++ clearIt () setIt (curId) PlayIt (curId)} function prePlay () {isStop = trueif (curId <0) {document. getElementById ("songName "). innerText = "no more songs. Please select the next song! "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 = "no songs currently !, View the playlist! "Return false} url = arrPL [cid]. url; curId = cidif (url = "None") {document. getElementById ("songName "). innerText = "Loading song not found! Play the next song! "NxtPlay () return false} document. getElementById (playid ). URL = urldocument. 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 = "no songs currently !, View the playlist! "Return false }} function InitPlay (songName, url, auto) {var strTemp ="\ N "strTemp + ="\ N "strTemp + ="\ N "strTemp + ="\ N "strTemp + ="\ N "strTemp + ="\ N "strTemp + ="\ N "strTemp + ="\ N "strTemp + ="\ N "strTemp + ="\ N "strTemp + ="\ N "strTemp + ="\ N "strTemp + ="\ N "strTemp + ="\ N "strTemp + ="\ N "strTemp + ="\ N "strTemp + ="\ N "strTemp + ="On-demand songs:
"+ SongName +"
"StrTemp + =" [] "strTemp + =" [play] "strTemp + =" [Stop] "if (arrPL. length-2)> = 0) {strTemp + = "[upper Qu]" strTemp + = "[lower Qu]"} strTemp + =""Document. getElementById ('player '). innerHTML = strTemptemptimer = setInterval ('showtimer () ', 1000);} function playX (cur) {PlayIt (cur) clearIt () setIt (cur) curId = curselected = cur} function MakeList (Id, Url, Name) {arrPL [cur] = new songObj (Id, Url, Name) cur ++} function loopIt () {if (isLoop) {document. getElementById ('sloop '). innerText = "no loop" isLoop = false} else {document. getElementById ('sloop '). innerText = "loop playback" isLoop = true}/* Code End */window. attachEvent ('onload', function () {InitPlay ("Female: muzhen SINGING: Wei Jiayi]", "http://happy369.com/yy/nrry.mp3", 1); playAndpauseIt ();}) scriptScript 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
MakeList parameters: three parameters in total. The first parameter is ID, the second parameter is the URL of music, and the third parameter is the name of the song. The instructions are all written in comments. You are welcome to read and reference them.