发布 shawl.qiu Javascript 媒体播放器 sqMusicPlayer v1.0 Final
说明:
为什么要写这个 web 播放器?
因为 web 多媒体是本人的死角! 为了摆脱这个死角, 最好的办法就是写个相关的东西出来.
这个播放器今天总算完成了预期功能, 我的初衷也得以实现了.
目录:
1. 功能介绍
2. 调用页演示
3. sqMusicPlayer v1.0 Final 核心源码
shawl.qiu
2007-05-11
shawl.qiu@gmail.com
下载:(由于体重原因, 不包含测试MP3)
http://shawl.qiu.googlepages.com/sqMusicPlayer_v1.0_Final.7z
http://files.myopera.com/btbtd/sqMusicPlayer/sqMusicPlayer_v1.0_Final.7z
内容:
1. 功能介绍
v1.0 Beta 没正式发布, 也就不说明功能了
sqMusicPlayer v1.0 Final 实现功能概述:
- 1. 支持从本地加载播放列表, Iframe 实现.(但这个功能由于目前没应用, 因此没去完成动态加载列表功能)
- 2. 支持 纯 js 跨域加载播放列表, 相关技术见:
- shawl.qiu javascript 跨域类... sqCrossDomain v1.0
- http://blog.csdn.net/btbtd/archive/2007/05/10/1603666.aspx
- 3. 支持自动播放列表
- 4. 支持以mqrquee 标签显示当前播放歌曲的标题
- 5. 支持动态设置默认播放歌曲
- 6. 支持动态显示播放器宽高大小
- 7. 支持动态设置默认为 Media 或 Real 播放器
- 8. 支持动态设置默认播放列表
- 9. 在播放列表页显示播放状态
- 10. 动态选择播放列表
- 11. 动态选择播放曲目
- 12. ... 这个播放器还有其他隐藏功能, 有兴趣的自己研究.
2. 调用页演示
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <!-- DW6 -->
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>shawl.qiu tesqPlayerlate</title>
- <style type="text/css">
- /* <![CDATA[ */
- #PlayerControl
- {
- padding:5px 2px;
- }
- /* ]]> */
- </style>
- <script type='text/javascript' src='sqMusicPlayer_v1.0_Final.js'></script>
- <script type="text/javascript">
- //<![CDATA[
- onload =
- function()
- {
- sqPlayer.IntiName = "sqPlayer";
- sqPlayer.OffsetSelect = 0;
- sqPlayer.Width = "130";
- sqPlayer.Height = "150";
- sqPlayer.Player.ID = "PlayerId";
- sqPlayer.Player.Media = true;
- //sqPlayer.Player.Real = true;
- sqPlayer.Player.Playlist = true;
- sqPlayer.List.DefaultList = 1;
- /* 从 iframe 加载列表 */
- /*
- sqPlayer.List.Iframe.ID = "PlayListIfm";
- sqPlayer.List.Iframe.Go();
- */
- /* 从 远程 域加载列表 */
- sqPlayer.Remote.Ms = 100;
- sqPlayer.Remote.Limit = 10000;
- sqPlayer.Remote.AddPlayList
- (
- "万维网列表 1",
- "http://files.myopera.com/btbtd/sqMusicPlayer/PlayList/network_playlist1_script.txt"
- );
- sqPlayer.Remote.AddPlayList
- (
- "本地列表 1",
- "/sqMusicPlayer/playlist/local_playlist1_script.txt"
- );
- sqPlayer.Remote.ScriptId="SptTextId";
- sqPlayer.Remote.VariableName = "ScriptText";
- sqPlayer.Remote.ErrorMsg = "加载列表时超时, 操作无法进行!";
- sqPlayer.Remote.Go()
- } // end onload
- //]]>
- </script>
- </head>
- <body>
- <!-- <iframe id="PlayListIfm" src="playlist/local_playlist1.txt" style='display:none;'></iframe> -->
- <div id="PlayerMain">
- </div>
- </body>
- </html>
- // shawl.qiu JavaScript Document
- /*-----------------------------------------------------------------------------------*/
- * shawl.qiu sqMusicPlayer class v1.0
- /*-----------------------------------------------------------------------------------*/
- //---------------------------------begin class sqMusicPlayer()-------------------------------//
- function sqMusicPlayer()
- { // shawl.qiu code
- //------------------------------------begin public variable
- //---------------begin about
- this.auSubject = 'shawl.qiu sqMusicPlayer class';
- this.auVersion = 'v1.0 Final';
- this.au = 'shawl.qiu';
- this.auEmail = 'shawl.qiu@gmail.com';
- this.auBlog = 'http://blog.csdn.net/btbtd';
- this.auCreateDate = '2007-5-7';
- this.auUpdate1 = '2007-5-11 v1.0 Final';
- //---------------end about
- this.Debug = false;
- this.ID = "PlayerMain";
- this.IntiName = "Mp";
- this.AutoPlay = false;
- this.OffsetSelect = 0;
- this.Width = "300";
- this.Height = "200";
- this.Player = {}
- this.Player.ID = "PlayerId";
- this.Player.Media = false;
- this.Player.Real = false;
- this.Player.Playlist = false;
- this.Player.ChangePlayer = fChangePlayer;
- this.Player.ChagneMusic = fChangeMusic;
- this.Player.Cmd = fPlayerCmd;
- this.Player.NextOrPrev = fPlayNextOrPrev;
- this.CurrentPlay = {};
- this.CurrentPlay.Index = function()
- {
- return Tl.OffsetSelect;
- }
- this.CurrentPlay.Path = function()
- {
- return Tl.List.Array[Tl.OffsetSelect][1];
- }
- this.Class = {};
- this.Class.Name = "PlayerMain";
- this.Control = {};
- this.Control.ID = "PlayerControl";
- this.Control.ClassName = "PlayerControl";
- this.Control.PlayByRadioID = "PlayerByRadio";
- this.Title = {};
- this.Title.ID = "PlayTitle";
- this.Title.Marquee = function(){}
- this.Title.Marquee.ID = "PlayTitleMid";
- this.Title.Marquee.Delay = "200";
- this.List = {};
- this.List.Viewer = fListViewer;
- this.List.Array = [];
- this.List.Path = [];
- this.List.Add = fAddList;
- this.List.DefaultList = 0;
- this.List.Prefix = "zdfjfkaLkjsdfjasL";
- this.List.Iframe = {};
- this.List.Iframe.ID = "PlayListIfm";
- this.List.Iframe.GetList = fGetListFromIfm;
- this.List.Iframe.Go = fIframeGo;
- this.Popup = fWinPopup;
- this.About = fAbout;
- this.Go = fGo;
- this.ListMethod = fListMethod;
- this.Random = fRandom;
- this.GetState = fGetState;
- this.Remote = {};
- this.Remote.Symbol = {};
- this.Remote.Symbol.Item = "|";
- this.Remote.Symbol.Song = "||";
- this.Remote.Ms = 100;
- this.Remote.Limit = 10000;
- this.Remote.ScriptUrl = "";
- this.Remote.ScriptId="SptTextId";
- this.Remote.VariableName = "ScriptText";
- this.Remote.CallBack = fRemoteCallBack;
- this.Remote.ErrorMsg = "加载列表时超时, 操作无法进行!";
- this.Remote.PlayList = [];
- this.Remote.AddPlayList = fAddPlayList;
- this.Remote.ChangeList = fRemoteChangeList;
- this.Remote.Go = fRemoteGo;
- //------------------------------------end public variable
- //------------------------------------begin private variable
- var Tl = this;
- var pPlayerMain = null;
- var pOffsetPlay = null;
- var pPlayer = null;
- var pMarquee = null;
- var pListPrefix = "zdfjfkaLkjsdfjasL";
- //------------------------------------end private variable
- //------------------------------------begin public method
- function fGetState()
- {
- if(Tl.Player.Real)
- {
- fAttachEvent(Tl.Player.ID, "OnPositionChange", fCkEnding);
- fAttachEvent(Tl.Player.ID, "OnPlayStateChange", fRealPlayStateChange);
- }
- if(Tl.Player.Media)
- {
- fAttachEvent(Tl.Player.ID, "EndOfStream", fCkEndingMedia);
- fAttachEvent(Tl.Player.ID, "PlayStateChange", fMediaPlayStateChange);
- }
- } // end function fGetState
- function fRealPlayStateChange(iNewState)
- {
- if(typeof(oPopup)=="object")
- {
- if(oPopup.closed)return false;
- var EleSpan = oPopup.document.getElementById("PlayStateId");
- if(EleSpan!=null)
- {
- EleSpan.innerHTML = fReturnPlayStateForReal(iNewState);//fReturnPlayStateForMedia(iNew);
- } // end if 1
- } // end if
- } // function fRealPlayStateChange
- function fMediaPlayStateChange(iOld, iNew)
- {
- if(typeof(oPopup)=="object")
- {
- if(oPopup.closed)return false;
- var Player = document.getElementById(Tl.Player.ID);
- var EleSpan = oPopup.document.getElementById("PlayStateId");
- if(EleSpan!=null)
- {
- EleSpan.innerHTML = fReturnPlayStateForMedia(iNew);
- } // end if 1
- /*
- var EleSpanPlayTotalTime = oPopup.document.getElementById("PlayTotalTime");
- if(EleSpanPlayTotalTime!=null)
- {
- EleSpanPlayTotalTime.innerHTML = fSecondToTime(Player.Duration);
- }
- */
- } // end if
- } // end function fMediaReadStateChange
- function fRemoteChangeList(sValue, EleSle)
- {
- sValue -=0;
- var bChangeList = oPopup.confirm("Now loadding new playlist <"+Tl.Remote.PlayList[sValue][0]+">?");
- if(!bChangeList)
- {
- EleSle.options[Tl.List.DefaultList].selected = true;
- return;
- }
- oPopup.alert("For loadding the new playlist, the window must be closing now.");
- oPopup.close();
- Tl.List.DefaultList = sValue;
- fRemoteGo();
- } // end fRemoteChangeList
- function fAddPlayList(sListName, sUrl)
- {
- if(!sListName||sListName=="")
- {
- alert("列表名出错!");
- return;
- }
- if(!sUrl||sUrl=="")
- {
- alert("路径出错!");
- return;
- }
- var iList = Tl.Remote.PlayList.length;
- Tl.Remote.PlayList[iList] = [];
- Tl.Remote.PlayList[iList][0] = sListName;
- Tl.Remote.PlayList[iList][1] = sUrl;
- }
- function fRemoteGo()
- {
- if(Tl.Remote.PlayList.length==0)
- {
- alert("列表数组为空!");
- return;
- }
- if(Tl.List.DefaultList>Tl.Remote.PlayList.length-1)
- {
- alert("选中的列表不存在, 现在切换至最末的列表!");
- Tl.List.DefaultList = Tl.Remote.PlayList.length-1
- }
- var Acd = new sqCrossDomain();
- Acd.Interval.Ms = Tl.Remote.Ms;
- Acd.Interval.Limit = Tl.Remote.Limit;
- Acd.Script.Url = Tl.Remote.PlayList[Tl.List.DefaultList][1];
- Acd.Script.ID = Tl.Remote.ScriptId
- Acd.Identifier.VariableName = Tl.Remote.VariableName
- Acd.CallBack = fRemoteCallBack;
- Acd.Error.Msg = Tl.Remote.ErrorMsg;
- Acd.Go();
- Acd = null;
- } // end function fRemoteGo
- function fRemoteCallBack(str)
- {
- // alert(str);
- var aItem = str.split(Tl.Remote.Symbol.Song);
- if(aItem.length==0)
- {
- alert("加载列表出错!");
- return;
- }
- var arReturn = [];
- for(var i=0, j=aItem.length; i<j; i++)
- {
- var aTemp = aItem[i].split(Tl.Remote.Symbol.Item);
- if(aTemp.length!=2)continue;
- var iNewAr = arReturn.length;
- arReturn[iNewAr] = [];
- arReturn[iNewAr][0] = aTemp[0];
- arReturn[iNewAr][1] = aTemp[1];
- } // end for
- Tl.List.Array = arReturn;
- fGo();
- }
- function fGo()
- {
- pPlayerMain = document.getElementById(Tl.ID);
- if(pPlayerMain==null)
- {
- alert("播放主域为 null!");
- return;
- }
- fIntiPlayerControl();
- if(Tl.List.Array.length==0)
- {
- alert("播放列表为空!");
- return;
- }
- if(Tl.List.Array[Tl.OffsetSelect]==null)
- {
- alert("当前播放曲目为 null!");
- return;
- }
- if(Tl.Player.Media)
- {
- pPlayerMain.innerHTML =
- fDisplayWmp
- (
- Tl.Width,
- Tl.Height,
- Tl.List.Array[Tl.OffsetSelect][1],
- 'PlayerMain',
- Tl.AutoPlay,
- Tl.Player.ID
- );
- }
- if(Tl.Player.Real)
- {
- pPlayerMain.innerHTML =
- fDisplayRm
- (
- Tl.Width,
- Tl.Height,
- Tl.List.Array[Tl.OffsetSelect][1],
- 'PlayerMain',
- Tl.AutoPlay
- );
- }
- pPlayer = document.getElementById(Tl.Player.ID);
- if(Tl.Player.Media)
- {
- pPlayer.Volume = -1;
- }
- if(Tl.Player.Playlist)
- {
- Tl.GetState();
- }
- } // end function fGo
- function fGetListFromIfm()
- {
- var sList = document.getElementById(Tl.List.Iframe.ID).contentWindow.document.body.innerHTML;
- sList = sList.replace(/<pre>|<//pre>/gi, "");
- var aItem = sList.split(/(/r/n|/n)/s*/1/);
- if(aItem.length==0)
- {
- alert("加载列表出错!");
- return;
- }
- var arReturn = [];
- for(var i=0, j=aItem.length; i<j; i++)
- {
- var aTemp = aItem[i].split(//r/n/);
- if(aTemp.length!=2)continue;
- var iNewAr = arReturn.length;
- arReturn[iNewAr] = [];
- arReturn[iNewAr][0] = aTemp[0];
- arReturn[iNewAr][1] = aTemp[1];
- } // end for
- return arReturn;
- }
- function fAddList(sName, sPath)
- {
- if(!sName||sName=="")
- {
- alert("列表名出错!");
- return;
- }
- if(!sPath||sPath=="")
- {
- alert("列表名出错!");
- return;
- }
- var iCur = Tl.List.Path.length;
- Tl.List.Path[iCur] = [];
- Tl.List.Path[iCur][0] = sName;
- Tl.List.Path[iCur][1] = sPath;
- } // return function fAddList
- function fIframeGo()
- {
- Tl.List.Array = Tl.List.Iframe.GetList();
- fGo();
- }
- function fCkEndingMedia(iResult)
- {
- var iNewPlay = Tl.OffsetSelect-0+1;
- if(iNewPlay<Tl.List.Array.length)
- {
- setTimeout
- (
- function()
- {
- var Player = document.getElementById(Tl.Player.ID);
- Player.Stop();
- Tl.OffsetSelect = iNewPlay;
- fPlayerCmd(Player.id, "play", Tl.List.Array[iNewPlay][1]);
- fAutoChangeSongSetting(iNewPlay);
- }
- ,
- 500
- ) ; // end setTimeout
- } // end if
- } // end function fCkEndingMedia
- function fCkEnding(iPos, iLen)
- {
- if(iPos==iLen)
- {
- var Player = document.getElementById(Tl.Player.ID);
- if(Player.GetPlayState()==0)
- {
- var iNewPlay = Tl.OffsetSelect-0+1;
- if(iNewPlay<Tl.List.Array.length)
- {
- fPlayerCmd(Player.id, "play", Tl.List.Array[iNewPlay][1]);
- Tl.OffsetSelect = iNewPlay;
- fAutoChangeSongSetting(iNewPlay);
- } // end if 2
- } // end if 1
- } // end if
- } // end function fCkEnding
- function fAutoChangeSongSetting(iNewPlay)
- {
- if(typeof(oPopup)=="object")
- {
- if(!oPopup.closed)
- {
- var EleOl = oPopup.document.getElementById("MusicList");
- if(EleOl!=null)
- {
- var EleLiSet = EleOl.getElementsByTagName("li");
- for(var i=0, j=EleLiSet.length; i<j; i++)
- {
- if(i==iNewPlay)
- {
- EleLiSet[i].style.backgroundColor = "yellow";
- }
- else
- {
- EleLiSet[i].style.backgroundColor = "white";
- }
- } // end for
- } // end if 3
- } // end if 2
- } // end if 1
- var EleMrq = document.getElementById(Tl.Title.Marquee.ID);
- if(EleMrq!=null)
- {
- EleMrq.innerHTML = Tl.List.Array[iNewPlay][0];
- }
- }
- function fAttachEvent(sId, sEvtName, Func)
- {// shawl.qiu script
- var Obj;
- if(typeof(sId)=="string")
- {
- Obj = document.getElementById(sId);
- } else if(typeof(sId)=="object")
- {
- Obj = sId;
- }
- if(Obj==null)
- {
- alert("无法对应的对象!");
- return false;
- } // end if 1
- if(document.addEventListener)
- {
- Obj.addEventListener(sEvtName, Func, false);
- }
- else if(document.attachEvent)
- {
- Obj.attachEvent(sEvtName, Func);
- } // end if
- } // end function fAttachEvent
- function fRandom()
- {
- var iIndex = fRandomBy(0, Tl.List.Array.length-1);
- var EleOl = oPopup.document.getElementById("MusicList");
- var EleLi = oPopup.document.getElementById("SongItem"+(iIndex));
- fChangeMusic(iIndex, EleLi, EleOl);
- }
- function fPlayerCmd(sPlayerId, sCmdName, sSongPath)
- {
- var oPlayer = document.getElementById(sPlayerId);
- if(!oPlayer)
- {
- alert('函数 fPlayerCmd 播放对象为 null!');
- return;
- }
- var sPlayer = "media";
- if(typeof(oPlayer.Source)!='undefined')
- {
- sPlayer='real';
- }
- switch(sPlayer)
- {
- case 'real':
- switch(sCmdName)
- {
- case 'stop':
- oPlayer.DoStop();
- break;
- case 'play':
- if(oPlayer.GetPlayState()==4)
- {
- oPlayer.DoPlay();
- }
- else
- {
- oPlayer.Source = sSongPath;
- oPlayer.DoPlay();
- }
- break;
- case 'pause':
- if(oPlayer.GetPlayState()==4)
- {
- oPlayer.DoPlay();
- }
- else
- {
- oPlayer.DoPause();
- }
- break;
- case 'mute':
- if(oPlayer.GetMute())
- {
- oPlayer.SetMute(false);
- }
- else
- {
- oPlayer.SetMute(true);
- }
- break;
- } // end switch 1
- break;
- default:
- switch(sCmdName)
- {
- case 'stop':
- oPlayer.stop();
- break;
- case 'play':
- if(oPlayer.PlayState==1)
- {
- oPlayer.Play();
- }
- else
- {
- oPlayer.FileName = sSongPath;
- oPlayer.AutoStart = true;
- oPlayer.Play();
- }
- break;
- case 'pause':
- if(oPlayer.PlayState==1)
- {
- oPlayer.Play();
- }
- else
- {
- oPlayer.Pause();
- }
- break;
- case 'mute':
- if(oPlayer.Mute)
- {
- oPlayer.Mute = false;
- }
- else
- {
- oPlayer.Mute = true;
- }
- break;
- } // end switch 1
- break;
- } // end switch
- } // end function fPlayerCmd
- function fChangeMusic(iMusicIndex, EleLi, EleOl)
- {
- var op = oPopup;
- var bCfm = true;
- if(bCfm)
- {
- var PlayThis = Tl.List.Array[iMusicIndex];
- if(PlayThis==null)
- {
- op.alert("haven't get this song!");
- return;
- }
- Tl.OffsetSelect = iMusicIndex;
- var LiSet = EleOl.getElementsByTagName('li');
- for(var i=0, j=LiSet.length; i<j; i++)
- {
- LiSet[i].style.backgroundColor = "white";
- }
- EleLi.style.backgroundColor = "yellow";
- var Player = document.getElementById(Tl.Player.ID); // PlayerTest
- var PlayUrl = encodeURI(Tl.List.Array[iMusicIndex][1]);
- if(typeof(Player.Source)=='undefined')
- {// media
- Player.FileName = PlayUrl;
- Player.AutoStart = true;
- Player.Play();
- }
- else
- { // real
- Player.Source = PlayUrl
- Player.DoPlay();
- } // end if 1
- pMarquee.innerHTML = "Song: "+Tl.List.Array[iMusicIndex][0];
- } // end if
- } // end function fChangeMusic
- function fPlayNextOrPrev(iIndex, bPrev)
- {
- if(!bPrev)
- {
- iIndex = iIndex-0;
- iIndex+=1;
- if(iIndex>Tl.List.Array.length-1)
- {
- oPopup.alert("couldn't get next song!");
- return;
- } // end if 1
- }
- else
- {
- iIndex = iIndex-0;
- iIndex-=1;
- if(iIndex<0)
- {
- oPopup.alert("couldn't get previous song!");
- return;
- } // end if 1
- } // end if
- var EleOl = oPopup.document.getElementById("MusicList");
- var EleLi = oPopup.document.getElementById("SongItem"+(iIndex));
- fChangeMusic(iIndex, EleLi, EleOl);
- } // end function fPlayNextOrPrev
- function fListViewer()
- {
- // fWinPopup('about:blank', 600, 500, ",status=yes");
- fWinPopup('about:blank', 600, 500);
- var Player = document.getElementById(Tl.Player.ID);
- var op = oPopup;
- op.document.title = Tl.auSubject+" "+Tl.auVersion;
- op.document.write
- (
- "<h2 style='text-align:center; color:red; font-weight:bold; margin:0px;'>",
- op.document.title,
- "</h2>"
- );
- op.document.write
- (
- "<div style='text-align:center;padding: 5px 0px;' id='ListCount'>",
- "<b>The play list has get <font color='red'>"+Tl.List.Array.length+"</font> Items.</b>",
- "</div>"
- );
- op.document.write("<div id='PlayListDivId' style='text-align:right'>");
- op.document.write
- (
- "<span style='float:right'>",
- /*
- " Pos:<span id='PlayCurretnPos'></span>",
- " Total:<span id='PlayTotalTime'></span> ",
- */
- "<b>PlayList</b>: "
- );
- op.document.write("<select onchange=/"opener."+Tl.IntiName+".Remote.ChangeList(this.value, this)/" "+
- ">");
- for(var i=0, j=Tl.Remote.PlayList.length; i<j; i++)
- {
- if(i==Tl.List.DefaultList)
- {
- op.document.write
- (
- "<option selected value="+i+">",
- Tl.Remote.PlayList[i][0],
- "</option>"
- );
- }
- else
- {
- op.document.write
- (
- "<option value="+i+">",
- Tl.Remote.PlayList[i][0],
- "</option>"
- );
- } // end if
- } // end for
- op.document.write("</select>");
- op.document.write("</span>");
- op.document.write("<span style='float:left'><b>State</b>: ");
- op.document.write("<span id='PlayStateId' style='color:fuchsia;'>");
- if(Tl.Player.Media)
- {
- op.document.write(fReturnPlayStateForMedia(Player.PlayState));
- };
- if(Tl.Player.Real)
- {
- op.document.write(fReturnPlayStateForReal(Player.GetPlayState()));
- }
- op.document.write("</span>");
- op.document.write("</span>");
- op.document.write("</div><br clear='both' />");
- var iCount = 0;
- op.document.write
- (
- "<div id='PlayerBar' style='text-align:left;font-weight:bold;background-color:whitesmoke; padding:2px;'>",
- "<span ",
- "onclick=/"opener."+
- Tl.IntiName+".Player.Cmd('"+
- Tl.Player.ID+"', 'mute')/" title='Mute'> Mute |",
- "</span>",
- "<span ",
- "onclick=/"if(confirm('stopping now?')){opener."+
- Tl.IntiName+".Player.Cmd('"+Tl.Player.ID+"', 'stop')}/" title='stop'> Stop |",
- "</span>",
- "<span ",
- "onclick=/"opener."+
- Tl.IntiName+".Player.Cmd('"+
- Tl.Player.ID+"', 'pause')/" title='Pause'> Pause |",
- "</span>",
- "<span ",
- "onclick=/"opener."+
- Tl.IntiName+".Player.NextOrPrev("+
- "opener."+Tl.IntiName+".CurrentPlay.Index(), true)/" title='Prev'> Prev |",
- "</span>",
- "<span ",
- "onclick=/"opener."+
- Tl.IntiName+".Player.NextOrPrev("+
- "opener."+Tl.IntiName+".CurrentPlay.Index(), false)/" title='Next'> Next |",
- "</span>",
- "<span ",
- "onclick=/"opener."+
- Tl.IntiName+".Random()/" title='Random'> Random | ",
- "</span>",
- "<span ",
- "onclick=/"opener."+
- Tl.IntiName+".Player.Cmd('"+
- Tl.Player.ID+"', 'play', opener."+Tl.IntiName+".CurrentPlay.Path())/" title='Play'> Play",
- "</span>",
- "</div>"
- );
- op.document.write("<ol id='MusicList' style='margin:8px auto;'>");
- for(var i=0, j=Tl.List.Array.length; i<j; i++)
- {
- var sBgCor = "";
- if(i==Tl.OffsetSelect)
- {
- sBgCor = "background-color:yellow;";
- }
- else
- {
- }
- op.document.write
- (
- "<li ",
- " style='padding:5px 2px;"+sBgCor+"'",
- " id=SongItem"+i,
- ">"
- );
- op.document.write
- (
- "<span style='float:right; font-weight:bold' >",
- "<span ",
- "onclick=/"opener."+
- Tl.IntiName+".Player.ChagneMusic('"+i+
- "', this.parentNode.parentNode, document.getElementById('MusicList'))/" title='play this'>▶ ",
- "</span>",
- "</span>",
- "Song: [<font color='black' style='font-weight:bold'>",
- Tl.List.Array[i][0]+"</font>]"
- );
- op.document.write
- (
- "<br/>Link: [<font color='blue'>",
- Tl.List.Array[i][1],
- "</font>]"
- );
- op.document.write("</li>");
- iCount++;
- } // end for
- op.document.write("</ol>");
- op.document.write
- (
- "<div style='text-align:right;background-color:gainsboro;padding:2px;'>",
- "<span onclick=/"if(confirm('close me now?')){opener=null;self.close();}/">",
- "close me",
- "</span>",
- "</div>"
- );
- op.document.write("<style>body{overflow-x:hidden;}<//style>");
- op.document.close();
- } // end function fListViewer
- function fIntiPlayerControl()
- {
- var TempDiv = document.getElementById(Tl.Control.ID);
- if(TempDiv==null)
- {
- var EleDiv = document.createElement("div");
- EleDiv.className = Tl.Control.ClassName;
- EleDiv.id = Tl.Control.ID;
- EleDiv.width = Tl.Width;
- var sMediaChecked = Tl.Player.Media?" checked":"";
- var sRealChecked = Tl.Player.Real?" checked":"";
- EleDiv.innerHTML="";
- EleDiv.innerHTML +=
- " Player: "+
- "<input type='radio' name="+Tl.Control.PlayByRadioID+" value=media"+
- " onclick="+Tl.IntiName+".Player.ChangePlayer(this) "+
- sMediaChecked+
- " />Media "+
- "<input type='radio' name="+Tl.Control.PlayByRadioID+" value=real"+
- " onclick='"+Tl.IntiName+".Player.ChangePlayer(this)' "+
- sRealChecked+
- " />Real"
- ;
- EleDiv.innerHTML += "<br/>";
- EleDiv.innerHTML +=
- " <a href='#' onclick='"+Tl.IntiName
- +".List.Viewer()' id='sqPlayerShowPlayListLk'>Play List</a>";
- EleDiv.innerHTML +=
- " <a href='#' onclick='"+Tl.IntiName
- +".About()'>About</a>";
- fInsertNode(pPlayerMain, EleDiv);
- }
- if(Tl.List.Array.length==0)return;
- var TempDiv = document.getElementById(Tl.Title.ID);
- if(TempDiv==null)
- {
- var EleDivTt = document.createElement("div");
- EleDivTt.className = Tl.Title.ID;
- EleDivTt.id = Tl.Title.ID;
- EleDivTt.style.width = Tl.Width+"px";
- EleDivTt.style.overflow = 'hidden';
- EleDivTt.innerHTML = "<marquee id="+Tl.Title.Marquee.ID+
- " SCROLLDELAY="+Tl.Title.Marquee.Delay+">Song: "+
- Tl.List.Array[Tl.OffsetSelect][0]+
- "</mqrquee>"
- ;
- fInsertNode(pPlayerMain, EleDivTt, "before");
- }
- pMarquee = document.getElementById(Tl.Title.Marquee.ID);
- }
- function fChangePlayer(obj)
- {
- var EleRadioSet = document.getElementsByName(Tl.Control.PlayByRadioID);
- var bChange = confirm('现在切换为 '+obj.value+' 播放器吗?');
- if(!bChange)
- {
- if(Tl.Player.Media)
- {
- EleRadioSet[0].checked = true;
- }
- else
- {
- EleRadioSet[1].checked = true;
- }
- return false;
- }
- switch(obj.value)
- {
- case "media":
- if(Tl.Player.Media)
- {
- alert('您已选择 Media 播放器, 不需要重复选择!');
- return;
- }
- Tl.Player.Real = false;
- Tl.Player.Media = true;
- break;
- default:
- if(Tl.Player.Real)
- {
- alert('您已选择 Real 播放器, 不需要重复选择!');
- return;
- }
- Tl.Player.Media = false;
- Tl.Player.Real = true;
- break;
- }
- var PlayUrl = Tl.List.Array[Tl.OffsetSelect][1];
- Tl.AutoPlay = true;
- if(Tl.Player.Media)
- {
- pPlayerMain.innerHTML =
- fDisplayWmp
- (
- Tl.Width,
- Tl.Height,
- PlayUrl,
- 'PlayerMain',
- Tl.AutoPlay,
- Tl.Player.ID
- );
- EleRadioSet[0].checked = true;
- } // end function fChangePlayer
- if(Tl.Player.Real)
- {
- pPlayerMain.innerHTML =
- fDisplayRm
- (
- Tl.Width,
- Tl.Height,
- PlayUrl,
- 'PlayerMain',
- Tl.AutoPlay,
- Tl.Player.ID
- );
- EleRadioSet[1].checked = true;
- } // end if
- pPlayer = document.getElementById(Tl.Player.ID);
- if(Tl.Player.Media)
- {
- pPlayer.Volume = -1;
- }
- if(Tl.Player.Playlist)
- {
- Tl.GetState();
- } // end if
- } // end function fChangePlayer
- function fDisplayWmp(iWidth, iHeight, sPath, sDivCssName, bAutoPlay, sPlayerId)
- {
- if(!sPath)
- {
- alert("wmp 路径 不能为空!");
- return;
- }
- sPath = encodeURI(sPath);
- sPath = sPath.replace(/^/s*|/s*$/g, "");
- if(!iWidth) iWidth = 500;
- if(!iHeight) iHeight = 68;
- if(!sDivCssName) sDivCssName = "Ubbwmp";
- if(!sPlayerId) sPlayerId = "PlayerId";
- return "<div class='"+sDivCssName+"'>"+
- "<object align=middle classid=CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95"+
- " class=OBJECT id="+sPlayerId+" width="+iWidth+" height="+iHeight+" >"+
- "<param name=ShowStatusBar value=-1>"+
- "<param name=uiMode value=mini>"+
- '<param NAME="enableContextMenu" VALUE="0">'+
- "<param name=Filename value="+sPath+">"+
- "<PARAM NAME=AUTOSTART VALUE="+bAutoPlay+">"+
- "<embed type=application/x-oleobject "+
- "codebase=http://activex.microsoft.com/activex/controls/mplayer/en/"+
- "nsmp2inf.cab#Version=5,1,52,701 flename=mp id='PlayerTest' src='"+sPath+"' width="+iWidth+" height="+iHeight+">"+
- "</embed>"+
- "</object>"+
- "</div>"
- ;
- } // end function fDisplayWmp
- function fDisplayRm(iWidth, iHeight, sPath, sDivCssName, bAutoPlay, sPlayerId)
- {
- if(!sPath)
- {
- alert("rm 路径 不能为空!");
- return;
- }
- sPath = encodeURI(sPath);
- sPath = sPath.replace(/^/s*|/s*$/g, "");
- if(!sDivCssName) sDivCssName = "Ubbrm";
- if(!sPlayerId) sPlayerId = "PlayerId";
- return "<div class='"+sDivCssName+"'>"+
- "<OBJECT classid=clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA"+
- " class=OBJECT id="+sPlayerId+" width="+iWidth+" height="+iHeight+">"+
- "<PARAM NAME=SRC VALUE="+sPath+">"+
- "<PARAM NAME=CONSOLE VALUE=Clip1>"+
- "<PARAM NAME=CONTROLS VALUE=imagewindow>"+
- "<PARAM NAME=AUTOSTART VALUE="+bAutoPlay+">"+
- "<param name=ShowStatusBar value=-1>"+
- "<PARAM NAME=StatusBar VALUE=-1>"+
- "<PARAM NAME=InfoPanel VALUE=-1>"+
- "<PARAM NAME=StatusPanel VALUE=-1>"+
- "<PARAM NAME=StatusField VALUE='get that'>"+
- '<param NAME="enableContextMenu" VALUE="0">'+
- "</OBJECT><br>"+
- "<OBJECT classid=CLSID:CFCDAA03-8BE4-11CF-B84B-0020AFBBCCFA"+
- " height="+32+" id=video2 width="+iWidth+">"+
- "<PARAM NAME=SRC VALUE="+sPath+">"+
- "<PARAM NAME=AUTOSTART VALUE="+bAutoPlay+">"+
- "<PARAM NAME=CONTROLS VALUE=controlpanel>"+
- "<PARAM NAME=NoLabels VALUE=false>"+
- "<PARAM NAME=CONSOLE VALUE=Clip1>"+
- "<PARAM NAME=StatusBar VALUE=-1>"+
- "<PARAM NAME=InfoPanel VALUE=-1>"+
- "<PARAM NAME=StatusPanel VALUE=-1>"+
- "<PARAM NAME=StatusField VALUE='get that'>"+
- "<param name=ShowStatusBar value=true>"+
- "</OBJECT>"+
- "</div>"
- ;
- } // end function fDisplayRm
- function fInsertNode(OldNode, NewNode, bBefore)
- {// shawl.qiu script
- var ParentNode = OldNode.parentNode;
- if(!ParentNode)return false;
- if(bBefore)
- {
- ParentNode.insertBefore(NewNode,OldNode);
- return false;
- } // end if
- ParentNode.replaceChild(NewNode, OldNode);
- ParentNode.insertBefore(OldNode, NewNode);
- } // end function fInsertNode
- //------------------------------------end public method
- //------------------------------------begin private method
- function fWinPopup(sUrl, iWidth, iHeight, sAddition){
- try{oPopup.close()}catch(e){}
- if(!sUrl)return false;
- if(!iWidth)iWidth=screen.availWidth-200;
- if(!iHeight)iHeight=screen.availHeight-150;
- if(!sAddition)sAddition='';
- var iMrgHor=(screen.availWidth-iWidth)/2;
- var iMrgVtc=(screen.availHeight-iHeight)/2;
- oPopup=open('about:blank','sqPopup','width='+iWidth+',height='+iHeight+',left='+iMrgHor
- +',top='+iMrgVtc+',scrollbars'+sAddition);
- oPopup.location.href=sUrl;
- oPopup.focus();
- oPopup.document.ondblclick=function(){oPopup.close();}
- oPopup.document.onkeydown=function(){ if(oPopup.event.keyCode==27)oPopup.close(); }
- return false;
- } // shawl.qiu script
- function fListMtd(obj, e){
- if(!e)var e=window.event;
- try{var sur=e.srcElement||e.target;}catch(e){}
- try{w.close();}catch(e){}
- w=open('','newwin','width=500,height=500,left=300,top=100,scrollbars');
- w.document.write('<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />');
- w.document.write('<style>body{width:400px;word-w.document.writeap: break-word;}</style>');
- w.focus();
- w.document.ondblclick=function(){w.close();}
- fListMtd(obj, w);
- try{w.onload=function(){ w.document.title=sur.firstChild.data;};}catch(e){}
- w.document.close();
- w.focus();
- return true;
- function fListMtd(obj, target){
- var ar=new Array();
- var j=0;
- for(var i in obj){
- try{
- ar[j]=i.bold()+' '+(typeof obj[i]).fontcolor('red')+
- ' '+(obj[i]+'').fontcolor('blue');
- j++;
- }catch(e){
- ar[j]=i.bold()+' '+(typeof obj[i]).fontcolor('red')+
- (' empty').fontcolor('red').bold()
- j++;
- }
- }
- ar=ar.sort();
- for(var i=0; i<ar.length; i++){
- target.document.write(i+1,'. ',ar[i],'<br/>');
- }
- return true;
- }
- } // end function fListMtd
- function fListMethod(obj, e)
- {
- fListMtd(obj, e);
- }
- function fAbout()
- {
- fWinPopup('about:blank', 600, 400);
- var op = oPopup;
- op.document.title = Tl.auSubject+" "+Tl.auVersion;
- op.document.write
- (
- "<h2 style='text-align:center; color:red; font-weight:bold'>",
- op.document.title,
- "</h2>"
- );
- op.document.write
- (
- "<div style='text-align:center;padding 5px 0px;' id='ListCount'>",
- "</div>"
- );
- op.document.write
- (
- "<div>",
- "<div style=float:left;text-align:left;font-weight:bold;>",
- "Subject: ",
- "</div>",
- "<div style=float:left;text-align:left;>",
- Tl.auSubject,
- "</div>",
- "</div>"
- );
- op.document.write("<br clear='both' />");
- op.document.write
- (
- "<div>",
- "<div style=float:left;text-align:left;font-weight:bold;>",
- "Version: ",
- "</div>",
- "<div style=float:left;text-align:left;>",
- Tl.auVersion,
- "</div>",
- "</div>"
- );
- op.document.write("<br clear='both' />");
- op.document.write
- (
- "<div>",
- "<div style=float:left;text-align:left;font-weight:bold;>",
- "Author: ",
- "</div>",
- "<div style=float:left;text-align:left;>",
- Tl.au,
- "</div>",
- "</div>"
- );
- op.document.write("<br clear='both' />");
- op.document.write
- (
- "<div>",
- "<div style=float:left;text-align:left;font-weight:bold;>",
- "E-Mail: ",
- "</div>",
- "<div style=float:left;text-align:left;>",
- Tl.auEmail.email(),
- "</div>",
- "</div>"
- );
- op.document.write("<br clear='both' />");
- op.document.write
- (
- "<div>",
- "<div style=float:left;text-align:left;font-weight:bold;>",
- "Blog: ",
- "</div>",
- "<div style=float:left;text-align:left;>",
- Tl.auBlog.link(),
- "</div>",
- "</div>"
- );
- op.document.write("<br clear='both' />");
- op.document.write
- (
- "<div>",
- "<div style=float:left;text-align:left;font-weight:bold;>",
- "Created Date: ",
- "</div>",
- "<div style=float:left;text-align:left;>",
- Tl.auCreateDate,
- "</div>",
- "</div>"
- );
- op.document.write("<br clear='both' />");
- op.document.write
- (
- "<div>",
- "<div style=float:left;text-align:left;font-weight:bold;>",
- "Update 1 : ",
- "</div>",
- "<div style=float:left;text-align:left;>",
- Tl.auUpdate1,
- "</div>",
- "</div>"
- );
- op.document.write("<br clear='both' />");
- op.document.write("<hr />");
- op.document.write
- (
- "<div>",
- "<div style=float:left;text-align:left;font-weight:bold;>",
- "Download: ",
- "</div>",
- "<div style=float:left;text-align:left;>",
- "</div>",
- "</div>"
- );
- op.document.write("<br clear='both' />");
- op.document.write
- (
- "<div>",
- "<div style=float:left;text-align:left;font-weight:bold;>",
- "Version 1.0 Final: ",
- "</div>",
- "<div style=float:left;text-align:left;>",
- ("http://files.myopera.com/btbtd/sqMusicPlayer/sqMusicPlayer_v1.0_Final.7z")
- .link("http://files.myopera.com/btbtd/sqMusicPlayer/sqMusicPlayer_v1.0_Final.7z"),
- "</div>",
- "</div>"
- );
- op.document.write("<br clear='both' />");
- op.document.write
- (
- "<div>",
- "<div style=float:left;text-align:left;font-weight:bold;>",
- "Version 1.0 Beta: ",
- "</div>",
- "<div style=float:left;text-align:left;>",
- ("http://files.myopera.com/btbtd/sqMusicPlayer/sqMusicPlayer_v1.0_Beta.7z")
- .link("http://files.myopera.com/btbtd/sqMusicPlayer/sqMusicPlayer_v1.0_Beta.7z"),
- "</div>",
- "</div>"
- );
- op.document.write("<br clear='both' />");
- op.document.write("<br/>");
- op.document.write
- (
- "<div style='margin:5px 0px; padding:2px;'>",
- "<div style=float:left;text-align:left;font-weight:bold;>",
- "Copyright: ",
- "</div>",
- "<div style=float:left;text-align:left;>",
- "© 2007-2010 shawl.qiu. All rights reserved.",
- "</div>",
- "</div>"
- );
- op.document.write("<br clear='both' />");
- op.document.write
- (
- "<div style='text-align:right;background-color:yellow;padding:2px;'"+
- " onclick=/"if(confirm('现在关闭窗口吗?')){opener=null;self.close();}/">close me</div>"
- );
- op.document.close();
- }
- String.prototype.email=function(sAddi){
- if(!sAddi)sAddi='';
- return fStrEmail(this,sAddi);
- }
- function fStrEmail(sEmail,sAddi){
- return '<a href="mailto:'+sEmail+'"'+sAddi+'>'+sEmail+'</a>'
- }
- function fRandomBy(under, over)
- {// shawl.qiu script
- switch(arguments.length)
- {
- case 1: return parseInt(Math.random()*under+1);
- case 2: return parseInt(Math.random()*(over-under+1) + under);
- default: return 0;
- } // end switch
- } // end function fRandomBy
- function fReturnPlayStateForMedia(iState)
- {
- switch(iState)
- {
- case 0:
- return "playback is stopped.";
- break;
- case 1:
- return "Playback is paused.";
- break;
- case 2:
- return "stream is playing...";
- break;
- case 3:
- return "Waiting for stream to begin.";
- break;
- case 4:
- return "Stream is Scanning forward...";
- break;
- case 5:
- return "Stream is Scanning in reverse...";
- break;
- case 6:
- return "stream has not been opened.";
- break;
- }
- return "";
- } // end function fReturnPlayStateForMedia
- function fReturnPlayStateForReal(iState)
- {
- //0:停止,1:连接,2:缓冲,3:播放,4:暂停,5:寻找
- switch(iState)
- {
- case 0:
- return "停止.";
- case 1:
- return "连接中...";
- case 2:
- return "缓冲中...";
- case 3:
- return "正在播放...";
- case 4:
- return "暂停.";
- case 5:
- return "寻找中";
- }
- } // end function fReturnPlayStateForReal
- function fSecondToTime(iIpt)
- {// shawl.qiu script
- var dt1 = new Date(0,0,0,0,0,iIpt);
- return dt1.toLocaleTimeString();
- } // end function fSecondToTime
- //------------------------------------end private method
- } // shawl.qiu code
- //---------------------------------end class sqMusicPlayer()---------------------------------//
- var sqPlayer = new sqMusicPlayer();
- /*-----------------------------------------------------------------------------------*/
- * shawl.qiu sqCrossDomain class v1.0
- /*-----------------------------------------------------------------------------------*/
- //---------------------------------begin class sqCrossDomain()-------------------------------//
- function sqCrossDomain()
- { // shawl.qiu code
- //------------------------------------begin public variable
- //---------------begin about
- this.auSubject = 'shawl.qiu sqCrossDomain class';
- this.auVersion = 'v1.0';
- this.au = 'shawl.qiu';
- this.auEmail = 'shawl.qiu@gmail.com';
- this.auBlog = 'http://blog.csdn.net/btbtd';
- this.auCreateDate = '2007-5-10';
- //---------------end about
- this.Interval = {};
- this.Interval.Ms = 100;
- this.Interval.Limit = 10000;
- this.Interval.Count = 1;
- this.Interval.Temp = 0;
- this.Interval.Func = null;
- this.Script = {};
- this.Script.Url = "";
- this.Script.ID = "SptTextId";
- this.Identifier = {};
- this.Identifier.VariableName = "";
- this.Prefix = "SADFkljkjfaksdskkk";
- this.CallBack = null;
- this.Error = {};
- this.Error.Msg = "加载超时!";
- this.Go = fGo;
- //------------------------------------end public variable
- //------------------------------------begin private variable
- var Tl = this;
- //------------------------------------end private variable
- //------------------------------------begin public method
- function fGo()
- {
- if(!Tl.CallBack)
- {
- alert("回调函数不能为空!");
- return;
- } // end if
- if(Tl.Script.Url=="")
- {
- alert("路径不能为空!");
- return;
- }
- var EleHeadSet = document.getElementsByTagName("head");
- if(EleHeadSet.length==0)
- {
- alert("Head 标签不存在, 操作无法进行!");
- return;
- }
- var EleHead = EleHeadSet[0];
- var EleSpt = document.createElement("script");
- EleSpt.src = Tl.Script.Url;
- EleSpt.id = Tl.Script.ID;
- EleHead.appendChild(EleSpt);
- Tl.Interval.Func =
- setInterval
- (
- function()
- {
- var sTemp = ""
- try
- {
- sTemp = eval(Tl.Identifier.VariableName);
- }
- catch(e)
- {
- sTemp = "";
- }
- defaultStatus = "空值: "+(sTemp=="")+" | 尝试加载次数: "+Tl.Interval.Count++;
- Tl.Interval.Temp += Tl.Interval.Ms;
- if(sTemp!="")
- {
- clearInterval(Tl.Interval.Func);
- Tl.CallBack(sTemp);
- var EleSpt = document.getElementById(Tl.Script.ID);
- if(EleSpt!=null)
- {
- var TempParent = EleSpt.parentNode;
- TempParent.removeChild(EleSpt);
- } // end if 1
- return false;
- } // end if
- if(Tl.Interval.Temp>=Tl.Interval.Limit)
- {
- clearInterval(Tl.Interval.Func);
- defaultStatus = Tl.Error.Msg;
- alert(Tl.Error.Msg);
- return false;
- }
- }
- ,
- Tl.Interval.Ms
- );
- } // end function fGo
- //------------------------------------end public method
- //------------------------------------begin private method
- //------------------------------------end private method
- } // shawl.qiu code
- //---------------------------------end class sqCrossDomain()---------------------------------//