www.gusucode.com > 仿51.com的php源码 1.1 > Music/musicnewsplay.js

    document.domain='www.wu-liao.com';
/*********Js Function Begin*********/
function AppXmlHttp()
{
	var A=null;
	try
	{
		A=new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			A=new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(oc)
		{
			if (typeof XMLHttpRequest != "undefined" );
			{
				A=new XMLHttpRequest();
			}
		}
	}
	return A;
}
function AppDelCookieMusic(name)
	//?Cookie
	{
		var exp = new Date();
		exp.setTime (exp.getTime() - 1);
		var cval = AppGetCookie (name);
		AppSetCookie(name, '', exp,'/','www.wu-liao.com');
		AppSetCookie(name, '', exp,'/Music','www.wu-liao.com');
	}
function AppSetCookie(name, value)
	//设定Cookie值
	{
		var expdate = new Date();
		var argv = AppSetCookie.arguments;
		var argc = AppSetCookie.arguments.length;
		var expires = (argc > 2) ? argv[2] : null;
		var path = (argc > 3) ? argv[3] : null;
		var domain = (argc > 4) ? argv[4] : null;
		var secure = (argc > 5) ? argv[5] : false;
		if(expires!=null) expdate.setTime(expdate.getTime() + ( expires * 1000 ))
			document.cookie = name + "=" + escape (value) +((expires == null) ? "" : ("; expires="+ expdate.toGMTString()))
		+((path == null) ? "" : ("; path=" + path)) +((domain == null) ? "" : ("; domain=" + domain))
		+((secure == true) ? "; secure" : "")
		delete value
	}
function AppGetCookie(name)
	//获得Cookie的原始值
	{
		var arg  = name + "=";
		var alen = arg.length;
		var clen = document.cookie.length;
		var i = 0;
		while (i < clen)
		{
			var j = i + alen;
			if (document.cookie.substring(i, j) == arg)
				return AppGetCookieVal(j);
			i = document.cookie.indexOf(" ", i) + 1;
			if (i == 0) break;
		}
		return null;
	}
function AppGetCookieVal(offset)
	//获得Cookie解码后的值
	{
		var endstr = document.cookie.indexOf (";", offset);
		if (endstr == -1)
			endstr = document.cookie.length;
		return unescape(document.cookie.substring(offset, endstr));
	}
/*********Js Function End*********/
var oXmlHttp = AppXmlHttp();
var cookiestr;
var TotalSongs;
var	playtype=0;
AppDelCookieMusic('PlayMusicData');
var _st = window.setTimeout;
window.setTimeout = function(fRef, mDelay) {
	if(typeof fRef == 'function'){
		var argu = Array.prototype.slice.call(arguments,2);
		var f = (function(){ fRef.apply(null, argu); });
		return _st(f, mDelay);
	}
	return _st(fRef,mDelay);
}
var	id=0;
//插入歌曲列表入口函数
function Insertsong(songstr){
	var tstr;
	tstr = songstr.split('\\|');
	if(tstr.length == 5){
		cookiestr = cookiestr + "\\#" + songstr;
		InitList();
	}
}
//容错代码
function killerror() {
	//alert("error");
}
window.onError = killerror;
//初始化歌曲列表过程
function InitList(){
	var songarray,htmlstr,i,j,tstr,ttstr,selectedindex;
	htmlstr = "<select size=\"22\" name=\"SongList\" id=\"SongList\" style=\"width:350px;border: 0px solid #333333;\" onclick=\"play();\">";
	songarray = cookiestr.split("\\#");
	TotalSongs = 0;
	for(i = 1;i < songarray.length;i++){
		tstr = songarray[i].split("\\|");
		if(tstr.length == 5){
			TotalSongs += 1;
			htmlstr += "<option value=\"" + songarray[i] + "\">";
			ttstr = TotalSongs + "." + unescape(tstr[1]);
			if(ttstr.length < 20){
				ttstr = ttstr.replace("**"," - ");
			}else{
				ttstr = ttstr.replace("**"," - ");
				ttstr = ttstr.substr(0,20) + "...";
			}
			htmlstr += ttstr + "</option>;";
		}
	}
	htmlstr += "</select>";
	var playlist = document.getElementById("playlist");
	playlist.innerHTML = htmlstr;
}
//播放歌曲
function play(){
	clearTimeout(id);
	if(SongList.selectedIndex < 0) {
		alert('请选择你要播放的曲目!');
	} else {
		var varvar,songurlstr,songnamestr,songsingerstr,songuserstr,songurlstr,songid,songlyricstr,songvolume=100;
		try{
			songvolume = Exobud.settings.volume;
		}catch(e){
			try{
				songvolume = document.Exobud.GetVolume();
			}catch(e){}
		}
		varvar = SongList.options[SongList.selectedIndex].value.split("\\|");
		songid = varvar[0];
		var MusicData = getMusicInfo(songid);
		if (MusicData != 'false') {
			var MusicArray = MusicData.split("\\|");
			songnamestr   = MusicArray[1];
			songsingerstr = MusicArray[2];
			songuserstr   = MusicArray[3];
			songurlstr    = MusicArray[4];
			songlyricstr  = MusicArray[5];
			var ex = songurlstr.split('.');
			var ext = ex[ex.length-1];
			if(songsingerstr.length > 10) {
				document.getElementById('songsinger').innerHTML = songsingerstr.substr(0,10) + "...";
			} else {
				document.getElementById('songsinger').innerHTML = songsingerstr;
			}
			if(songnamestr.length > 10) {
				document.getElementById('songname').innerHTML = songnamestr.substr(0,10) + "...";
			} else {
				document.getElementById('songname').innerHTML = songnamestr;
			}
			document.getElementById('songlyric').value="歌词:\r\n" + songlyricstr;
			document.title = songnamestr;
			if (ext == 'rm' || ext == 'ram' || ext == 'ra') {
				playtype=1;
				document.getElementById('bfr').style.display = '';
				document.getElementById('bfm').style.display = 'none';
				Exobudm.controls.stop();
				try{
					Exobudr.setSource(songurlstr);
					Exobudr.DoPlay();
					Exobudr.SetVolume(songvolume);
				}catch(e){}
			} else {
				playtype=0;
				document.getElementById('bfr').style.display = 'none';
				document.getElementById('bfm').style.display = '';
				try{
					Exobudr.DoStop();
				}catch(e) {}
				Exobudm.URL = songurlstr;
				Exobudm.controls.play();
				Exobudm.settings.volume = songvolume;
			}
			id=window.setTimeout(showTLab,1000,ext);
			return;
		}
	}
}
//控制按钮 上一首
function Last_OneOK(){
	if (SongList.selectedIndex == 0) {
		SongList.options[SongList.options.length - 1].selected = true;
	} else if((SongList.selectedIndex > 0) && (SongList.selectedIndex < TotalSongs)){
		SongList.options[SongList.selectedIndex - 1].selected = true;
	}
	play();
}
//控制按钮 下一首
function Next_OneOK(){
	if((SongList.selectedIndex >= 0) && (SongList.selectedIndex < TotalSongs - 1)){
		SongList.options[SongList.selectedIndex + 1].selected = true;
	} else if (SongList.selectedIndex >= (TotalSongs - 1)) {
		SongList.options[0].selected = true;
	}
	play();
}
function Del_Music() {
	clearTimeout(id);
	var num = SongList.selectedIndex;
	var tmp = SongList.options[SongList.selectedIndex].value;
	tmp1 = tmp.split('\\|');
	songid = tmp1[0];
	musicplayliststr = AppGetCookie('MusicPlayList1');
	if (musicplayliststr) {
		var musicplaylist = musicplayliststr.split('\\|');
		var str = '';
		for(i=0; i < musicplaylist.length;i++) {
			tmp = musicplaylist[i].split(',');
			if (parseInt(tmp[0]) == songid) {
				musicplaylist[i] = null;
				TotalSongs--;
			} else {
				str = str + musicplaylist[i] + '\\|';
			}
		}
		str=str.substring(0,(str.length - 2));
		AppSetCookie('MusicPlayList1', str, null,'/Music', 'www.wu-liao.com');
		var sl = document.getElementById('SongList');
		sl.remove(num);
		if (sl.length == 0) {
			var nomusic = document.createElement("option");
			nomusic.text="1.列表中没有任何音乐。";
			sl.add(nomusic);
		}
		if (sl.options[num]) {
			sl.options[num].selected = true;
		} else {
			sl.options[0].selected = true;
		}
		play();
	}
}
var rplay=0;
function showTLab(ext){
	if(playtype==0) {
		ext="mp3";
	}
	else {
		ext="rm";
	}
	if(ext == 'rm' || ext == 'ram' || ext == 'ra') {
		try{
			if(Exobudr.GetPlayState()==3) rplay=1;
				if (rplay==1 && Exobudr.GetPlayState() <= 1) {
					clearTimeout(id);
					Next_OneOK();
					rplay=0;
				}
		}catch(e) {
			SongList.options[SongList.selectedIndex].text+=" (提示:没有安装realplay无法播放)";
			clearTimeout(id);
			Next_OneOK();
		}
	} else {
		if(Exobudm.playState == 1) {
			clearTimeout(id);
			Next_OneOK();
		}
	}
	id=window.setTimeout(showTLab,1000,ext);
	//setTimeout("showTLab(ext)",1000);
}
function getMusicInfo(id) {
	var d = AppGetCookie('PlayMusicData');
	if (d != null && d[id]) {
		return d[id];
	} else {
		try {
			oXmlHttp.open("GET", "GetMusicInfo.php?id=" + id, false);
			oXmlHttp.send(null);
			if(oXmlHttp.status == 200)
			{
				var str =  oXmlHttp.responseText;
				return str;
			}else{
				return -1;
			}
		} catch (e) {
			//do nothing
		}
	}
}

iplayliststr = AppGetCookie('MusicPlayList1');
if (iplayliststr) {
	imusicplaylist = iplayliststr.split('\\|');
	for(i = 0; i < imusicplaylist.length; i++) {
		var tmp2 = imusicplaylist[i].split(',');
		Insertsong(tmp2[0] + '\\|' + tmp2[1] + '\\|'+'1'+'\\|'+'1'+'\\|'+tmp2[0]);
	}
} else {
	Insertsong('\\|列表中没有任何音乐。\\|1\\|1\\|1');
}
SongList.options[0].selected = true;
play();
function CopyURL(){
	clipboardData.setData("text",URLTmp);
	alert("地址复制完毕,按Ctrl+V粘贴给网友吧!");
}
function CTextNoTips(){
	clipboardData.setData('text',URLTmp);
	document.all.PageAddress.select();
}