<?php
/*
'**************************************************************************************************
' 程序名称: CCTVAI开源音乐管理系统
' 官方网站: http://www.cctvai.com
' 联系 Q Q: 1542367792
' QQ交流群：136687984
' 版本：(终结版)
' 备注：未经书面授权，不得向任何第三方提供本软件系统！
' 功能，模板，插件，扩展，定制请联系QQ：1542367792
'**************************************************************************************************
*/
error_reporting(0); 
include "../include/cctvai.conn.php";
$id=SafeRequest("id", "get");
if(cd_mobile=="no"){header("Location:".LinkUrl("malbum", 1, 1, $id)."");exit();}
if(cd_mobilepc=="no"){if (!isMobile()){header("Location:".LinkUrl("malbum", 1, 1, $id)."");exit();}}
$error="您访问的Url页面不存在，请检查Url是否正确或包含非法字符！";
if(!IsNumID($id)) {exit(include _cctvai_root_ . "/include/error/content_error.php");}
$malbum=$db->getrow('select * from ' . tname('malbum') . " where CD_ID='" . $id . "'");
$db->query('update ' . tname('malbum') . " set CD_Hits=CD_Hits+1 where CD_ID='" . $id . "'");
?>
<!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">
 <head> 
  <meta http-equiv="Content-Type" content="text/html; charset=gbk" /> 
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0;" /> 
  <meta name="apple-mobile-web-app-capable" content="yes" /> 
  <meta name="apple-mobile-web-app-status-bar-style" content="black" /> 
  <meta name="format-detection" content="telephone=no" /> 
  <title><?php echo $malbum["CD_Name"]?>歌单-<?php echo cd_webname?>手机版</title> 
  <meta name="keywords" content="<?php echo $malbum["CD_Name"]?>,<?php echo cd_webname?>手机版" /> 
  <meta name="description" content="<?php echo $malbum["CD_Name"]?>" /> 
  <link rel="stylesheet" href="css/style.css" type="text/css" />
  <link rel="stylesheet" href="css/malbum.css" type="text/css" />
  <script type="text/javascript" src="js/jquery.js"></script>
 </head> 
 <body> 
  <div class="x5_wap"> 
   <header class="x5_heads"> 
    <a href="singer/index.php?id=<?php echo GetAlias("cctvai_user", "cd_id", "cd_name", $malbum['CD_User'])?>">
	<img src="<?php echo linkuserphoto(GetAlias("cctvai_user", "cd_id", "cd_name", $malbum['CD_User']), 48)?>" class="head-bg-blur" /> 
    <div class="pabg"></div> 
    <img src="<?php echo linkuserphoto(GetAlias("cctvai_user", "cd_id", "cd_name", $malbum['CD_User']), 48)?>" class="head-avatar" /> 
    <p class="head-name box ellipsis txt-shadow"><?php echo GetAlias("cctvai_user", "cd_nicheng", "cd_name", $malbum['CD_User'])?>&nbsp;个人空间&nbsp;<span style="font-size: 12px;"></span></p> 
    <div class="head-sign box ellipsis txt-shadow"> 
     <p class="ellipsis"><?php echo GetAlias("cctvai_user", "cd_sex", "cd_name", $malbum['CD_User'])?>&nbsp;&nbsp;分享：<?php echo GetAlias("cctvai_user", "cd_djmub", "cd_name", $malbum['CD_User'])?>个作品&nbsp;&nbsp;粉丝：<?php echo GetAlias("cctvai_user", "cd_ufans", "cd_name", $malbum['CD_User'])?></p> 
    </div> </a>
   </header> 
<div class="x5_weizhi"><a href="index.php" title="首页">首页</a> &gt; <a href="malbum.php" title="歌单专辑">歌单专辑</a> &gt; 专辑播放</div>
   <div class="malbum"> 
    <div class="pic"><img src="<?php echo LinkPicUrl($malbum['CD_Pic'],"malbum");?>"/></div> 
    <div class="title"><h1><?php echo $malbum["CD_Name"]?></h1></div> 
    <div class="cDGray"> 
     <ul> 
      <li>所属歌手：<span><a href="artist_p.php?id=<?php echo $malbum['CD_Singer']?>" target="_blank"><?php echo GetAlias('cctvai_singer', 'CD_Name', 'CD_ID', $malbum['CD_Singer'])?></a></span></li> 
      <li>所属分类：<span><a href="malbum_list.php?id=<?php echo $malbum['CD_ClassID']?>" target="_blank"><?php echo GetAlias("cctvai_malbumclass", "CD_Name", "CD_ID", $malbum['CD_ClassID'])?></a></span></li> 
      <li>发行公司：<span><?php echo $malbum['CD_GongSi']?></span></li> 
      <li>唱片语言：<span><?php echo $malbum['CD_YuYan']?></span></li> 
      <li>发行时间：<span><?php echo date('Y-m-d',strtotime($malbum['CD_AddTime']))?></span></li> 
	  <li>人气指数：<span><?php echo $malbum['CD_Hits']?></span></li> 
     </ul> 
    </div> 
    <div class="lrc">歌单介绍：<?php echo str_checkhtml($malbum['CD_Intro'])?></div> 
   </div> 
<!-- Baidu Button BEGIN -->
<div style="padding: 10px;">
<div id="share_label" style="border-bottom: none"><span>分享到 : </span></div>
  <div class="bdsharebuttonbox">
   <a href="#" class="bds_more" data-cmd="more"></a>
   <a href="#" class="bds_qzone" data-cmd="qzone" title="分享到QQ空间"></a>
   <a href="#" class="bds_tqq" data-cmd="tqq" title="分享到腾讯微博"></a>
   <a href="#" class="bds_weixin" data-cmd="weixin" title="分享到微信"></a>
   <a href="#" class="bds_sqq" data-cmd="sqq" title="分享到QQ好友"></a>
   <a class="bds_count" data-cmd="count"> </a>
  </div> 
  <script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"32"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script>
</div>
<!-- Baidu Button END -->
   <div class="malbum-list"> 
    <div class="head"><strong>歌单列表</strong></div> 	
   </div> 

<section id="content"></section>
	<section id="playwrap">
		<div id="playContent">
			<div >
				<audio  id="myMusic"></audio>
			</div>
			<div onClick="myControl.selectTime(event)" id="progressWrap">
				<div id="progress"></div>
			</div>
			<div class="img">
				<img id="singerHead" src="images/special.png">
			</div>
			<div class="info">
				<div class="songname clearfix">
					<label id="musicTitle" for="musicTitle">畅享好音乐</label>
					<label style="display: none;" id="songname" for="songname" style="color: rgb(204, 0, 0);">此手机不支持html5播放，扔了吧</label>
					<label id="timeshow" for="time"><span id="currentTime">00:00</span>/<span id="totleTime">00:00</span></label>
				</div>
				<div class="audioControl"style="margin-left: 10px;">
					<a id="prevButton" class="last" onClick="myControl.prev()" href="javascript:;"></a>
					<a id="playButton" class="play" onClick="myControl.mainControl()" href="javascript:;"></a>
					<a id="nextButton" class="next" onClick="myControl.next()" href="javascript:;"></a>
					<a id="modeButton" class="mode-default" onClick="myControl.selectMode()" href="javascript:;"></a>
					<a class="border"></a>
					<a id="playDetail" class="showDetail" href="javascript:;"></a>
				</div>
			</div>
		</div>
	</section>
<div style="display:none;" id="oWindow">cctvai</div>
  </div> 
<script type="text/javascript">
//歌曲列表
var Zzx = function(o){
	this.setting     = (typeof o === 'object') ? o : {};
	this.target 	 = this.setting.target || 'newSong';
	this.type        = typeof this.setting.type === 'number' ? this.setting.type : parseInt(this.setting.type);
	this.firstCount  = typeof this.setting.firstCount === 'number' ? this.setting.firstCount : parseInt(this.setting.firstCount);
	this.Count  	 = typeof this.setting.Count === 'number' ? this.setting.Count : parseInt(this.setting.Count);
	this.content     = $("#content");					
	//初始化
	this.init();		
}

Zzx.prototype ={
	init:function(){
		//列表初始化
		this.content.html("");
		//堆栈指针初始化
		this.stack = 0;
		//图片路径
		this.imgPath = '';		
		//定时器
		this.timer = null;			
		//测试JSON数据（可以替换为AJAX请求返回值）
		this.testJson = {
list:[<?php
if($malbum["CD_Song"]){
	$dsql="and CD_ID in(".$malbum["CD_Song"].") ";
}else{
	$dsql="and CD_ID in(0) ";
}
$sqlclass="select * from " . tname('dj') . " where 1=1 $dsql or CD_SpecialID='" . $id . "' and CD_Passed=0 and CD_Deleted=0 and CD_ClassID<>0  Order by UNIX_TIMESTAMP(CD_AddTime) desc";
$results=$db->query($sqlclass);
if($results) {
	while($dj=$db->fetch_array($results)) {
		$a=$a+1;
$server=$db->getrow("select * from " . tname('server') . " where CD_ID=" . $dj['CD_Server'] . "");
$playurl=$server['CD_Url'].$dj['CD_Url'];
echo'{src:"",title:"'.$a.'.'.$dj['CD_Name'].'",singer:"'.GetAlias('cctvai_singer', 'CD_Name', 'CD_ID', $dj["CD_Singer"]).'",song:"'.$playurl.'"},
';
	}
}
?>
]
						}
		this.createList(true);
		this.addHandle();
	},
	
	//创建内容列表
	createList:function(boolen){		
		//boolen:true/false确定是否初次载入，
		this.ulNode = document.createElement("ul");
		this.ulNode.id = this.target+"list";
		this.content.append(this.ulNode);
		this.ulTarget = $("#"+this.ulNode.id);
		this.createMore();
		this.loadList(boolen);
	},
	
	//创建更多按钮
	createMore:function(){	
		this.moreNode = document.createElement("div");
		this.moreNode.className = 'm';
		this.moreNode.innerHTML = '更多';
		this.moreNode.id = this.target+'more';
		this.moreTarget = $("#"+this.moreNode.id);
	},
	
	//加载列表	
	loadList:function(boolen){		
		var oList = this.testJson.list;
		var oLength;		
		if(boolen){  //计算加载歌曲数
			oLength = oList.length > this.firstCount ? this.firstCount: oList.length;			
		}else{
			oLength = (oList.length-this.stack) > this.Count ? this.Count: (oList.length-this.stack);				
		}	
		if(oLength<=0){
			this.moreTarget.text("这是最后一页了！");
		};
		
		if(!this.moreTarget[0]){
			this.content.append(this.moreNode);				
		};
		
		for(var i = 0 ; i < oLength ; i++){				
			this.loadDate(oList);
		}
		
	},
	
	//加载列表数据	
	loadDate:function(oList){			
		switch(this.type){  
			//根据不同的模块 定制不同的数据展示形式
			case 1:this.ulTarget.append('<li onclick="myControl.selectList(this,'+this.stack+')">'
									  + '<div class="frmPlay"><i></i></div>'
									  + '<span style="display:none;" class="musicData" title='+oList[this.stack].title+'  value='+oList[this.stack].song+'></span>'
									  + '<div class="textBox"><p>'+oList[this.stack].title+'-'+oList[this.stack].singer+'</p></div>'
									  + '</li>');
										break;
			case 2:this.content[0].innerHTML  = '此模块建设中...';
										break;
			default :alert("该模块出错！");
		}
		this.stack+=1;
	},
	
	//绑定事件
	addHandle:function(){
		var that = this;
		$("#"+this.moreNode.id).bind('click',function(){
			//加载更多列表
			that.createList(false);
		});
	}
	
}
//播放器控制面板	
var Control = function(o){
	this.setting         = (typeof o === 'object')? o : {};		
	this.audio           = this.setting.audio;
	this.progressWrap    = this.setting.progressWrap;
	this.playModeNode    = this.setting.playModeNode;
	this.playBtn         = this.setting.playBtn;
	this.playTitle       = this.setting.playTitle;
	this.singerHead      = this.setting.singerHead;
	this.progress        = this.setting.progress;
	this.oWinObj         = this.setting.oWinObj;
	this.allTimeNode     = this.setting.allTimeNode;	  
	this.currentTimeNode = this.setting.currentTimeNode;  
	this.path            = '';  //歌曲路径（相对于html）
	this.imgPath         = '';   //图片路径（相对于html）
	this.init();
}

Control.prototype = {	
	//初始化
	init:function(){
		//播放控制	
		this.start = true;
		//定时器
		this.timer = null;				
		this.audio.src = null;			
		//可选播放模式
		this.ModeData = [
			{mode:'default',text:'顺序播放模式'},
			{mode:'random',text:'随机播放模式'},
			{mode:'single',text:'单曲循环模式'}
		];
		//默认播放模式
		this.ModeIndex = 0;
		this.playMode = this.ModeData[this.ModeIndex].mode;	
	},
	
	//选择歌曲列表
	selectList:function(_this,stack){	
		var allow = true;
		var index = null;
		this.oLi = _this;
		this.oUl = _this.parentNode;	
		if(index == stack && !this.start ){
			allow = false;
		}
		index = stack;
		this.loadMusic();
		if(allow){
			this.goPlay();
		}else{
			this.goPause();
		}											
	},
	
	//上一首
	prev:function(){
		if(this.oLi.previousSibling!=null){	
			this.oLi = this.oLi.previousSibling;
			this.loadMusic();
		}else{
			this.oWindow("已经是第一首了哦！");
		}
		this.goPlay();
	},
	
	//主控
	mainControl:function(){
		if(this.start){
			this.goPlay();
		}else{
			this.goPause();
		}	
	},
	
	//下一首
	next:function(){
		if(this.oLi.nextSibling!=null){
			this.oLi = this.oLi.nextSibling;
			this.loadMusic();
		}else{
			this.oWindow("已经是最后一首了哦！")
		}
		this.goPlay();
	},
	
	//播放模式选择
	selectMode:function(){
		this.ModeIndex = (this.ModeIndex<(this.ModeData.length-1))?(this.ModeIndex+1):0;
		this.playMode = this.ModeData[this.ModeIndex].mode;
		this.oWindow(this.ModeData[this.ModeIndex].text);
		this.playModeNode.attr("class","mode-"+this.playMode);
	},
	
	//播放进度选择
	selectTime:function(event){
		var moveTo = event.pageX - this.progressWrap.offset().left;
		this.audio.currentTime = moveTo/parseInt(this.progressWrap.css("width"))*this.audio.duration;
		this.progress.css("width",moveTo+"px");
	},
	
	//自动播放
	autoPlay:function(){
		//监听歌曲结束
		var that = this;
		this.audio.addEventListener('ended', function () {
			if(typeof that.playMode==='string')
			{	//播放模式判断	
				switch(that.playMode){
					case 'default': that.oLi = (that.oLi.nextSibling!=null)?that.oLi.nextSibling:that.oUl.childNodes[0];
									break;
					 case 'random': that.oLi = that.oUl.childNodes[Math.round(Math.random()*(that.oUl.childNodes.length-1))];
									break;
					 case 'single': ;
						   default: ;
				}
				that.loadMusic();
				that.goPlay();
			}else{
				that.oWindow("循环类型不符!");		
			}
		},false);
	},
	
	//加载要播放的歌曲
	loadMusic:function(){
			$obj = $(this.oLi)
			var song = $obj.find(".musicData").attr("value");	
			var pic = $obj.find(".musicData").attr("pic");
			var title = $obj.find(".musicData").attr("title");
			//this.singerHead.attr("src",this.imgPath + pic)
			this.audio.src = this.path + song;
			this.playTitle.html(title);
	},
	
	//判断当前是否歌曲列表
	songReady:function(){
		if(!this.audio.src){
			this.oWindow("请先点击列表播放！")
			return false;
		}else{
			return true;
		}
	},
	
	//转换为时间格式
	timeDispose:function (number) {
		var minute = parseInt(number / 60);
		var second = parseInt(number % 60);
		minute = minute >= 10 ? minute : "0" + minute;
		second = second >= 10 ? second : "0" + second;
		return minute + ":" + second;
	},	
	
	//自定义提示框
	oWindow:function(oText){
		this.oWinObj.show();
		this.oWinObj.html(oText);
		var doc = document.documentElement;
		var oWinX = (doc.clientWidth - this.oWinObj[0].offsetWidth)/2;
		var oWinY = (doc.clientHeight - this.oWinObj[0].offsetHeight-50)/2;
		this.oWinObj.css('left',oWinX+'px');
		this.oWinObj.css('top',oWinY+'px');
		var _this = this;
		setTimeout(function(){_this.oWinObj.hide();},1000)
	},
	
	//播放时间
	oTime:function(){
		if(this.audio.readyState >=4){
			var currentProgress = Math.round(this.audio.currentTime/this.audio.duration*parseInt(this.progressWrap.css("width")));
			this.progress.css("width",currentProgress+"px");
			this.allTimeNode.html(this.timeDispose(this.audio.duration));
			this.currentTimeNode.html(this.timeDispose(this.audio.currentTime));
		}
	},
	
	//播放
	goPlay:function(){
		if(this.songReady()){		
			this.audio.play();
			var _this = this;
			this.goPlayStyle();
			this.timer = setInterval(function(){_this.oTime()},1000)
			this.start = false;
			this.autoPlay();
		}
	},
	
	//暂停
	goPause:function(){
		this.audio.pause();
		this.goPauseStyle();
		clearInterval(this.timer);
		this.start = true;
	},
	
	//播放样式
	goPlayStyle:function(){
		var $oLiIndex = $(this.oLi);
		$(".frmPause").removeClass("frmPause");
		$oLiIndex.find(".frmPlay").addClass("frmPause");				
		this.playBtn.addClass("pause");
		this.playBtn.removeClass("play");
	},
	
	//暂停样式
	goPauseStyle:function(){
		var $oLiIndex = $(this.oLi);
		$(".frmPause").removeClass("frmPause");
		this.playBtn.addClass("play");
		this.playBtn.removeClass("pause");	
	}			
}

function ZzxMusic(){

	var aa={};
	//模块设置
	var setting = {
		newSong:{'target':'newSong','type':'1','firstCount':15,'Count':5},
		songCharts:{'target':'newSong','type':'1','firstCount':2,'Count':4},
		singer:{'target':'newSong','type':'1','firstCount':8,'Count':7},
		radioStation:{'target':'newSong','type':'1','firstCount':9,'Count':2}
	};
	
	//默认加载模块
	aa.newSong = new Zzx(setting.newSong);	
	
	//模块初始化
	$(".menu_tagList").children("li").bind('click',function(){
		for(var i in setting){
			if($(this).attr("id")==i){
				if(typeof aa[i]==='undefined'){
					aa[i] = new Zzx(setting[i]);
				}else{
					aa[i].init();
				}				
			}
		}
		$(".menu_hover").removeClass("menu_hover");
		$(this).addClass("menu_hover");
	})		
}

//实例化控制台
var myControl = new Control({
			 audio : document.getElementById("myMusic"), //播放器
	  playModeNode : $("#modeButton"),	 //模式选择按钮
		   playBtn : $("#playButton"),   //主控按钮
		 playTitle : $("#musicTitle"),   //歌曲TITLE容器
		singerHead : $("#singerHead"),   //歌曲插图容器
	  progressWrap : $("#progressWrap"), //歌曲进度条容器
		  progress : $("#progress"),     //歌曲进度条
		   oWinObj : $("#oWindow"),		 //警告窗容器
	   allTimeNode : $("#totleTime"),    //当前时间容器
   currentTimeNode : $("#currentTime")   //当前时间容器
});	

ZzxMusic();	

</script>
 </body>
</html>