var videoblock;
var recordblock;
//实时播放视频组件
function initBlock(){
	var uuid = $.uniqueId();
	videoblock = $.videoBlock({
		uuid : uuid,
		title : "",
		$baseContainer : $("#video"),
		$content:$("#video"),
		serverConnection : top.serverConnection,
		monid : null,
		isRunning : false,
		onRightClick : $.noop()
	});
	BlockCacher.addBlock(videoblock);
	$("#video video").attr("id",videoblock.videoId);
}
function webrtc_startVideo(sbbh,tdbh,tdmc){
	videoblock.setFdId(sbbh).setChannelId(tdbh).setHideTitle(tdmc).startMonitor();
}
//历史视频播放组件
function initRecordBlock(){
	var uuid = $.uniqueId();
	recordblock = $.recordblock({
		uuid : uuid,
		title : "",
		$baseContainer : $("#record"),
		$content:$("#record"),
		serverConnection : top.serverConnection,
		monid : null,
		isRunning : false,
		onRightClick : $.noop()
	});
	BlockCacher.addBlock(recordblock);
	$("#record video").attr("id",recordblock.videoId);
}
function webrtc_startRecord(sbbh,tdbh,tdmc,startTime,endTime){
	/*var sbbh = "201805031342536402";
	var tdbh = "1";
	var tdmc = "TTTTTTTTTTT";
	var playbackurl = "";
	var start_occur= "";
	var end_occur = "";
	var curDate = "2018-06-13 13:13:13";
	if($('#occurTime').html()){
		//curDate = $('#occurTime').html();
	}*/
	//console.log(sbbh+"=回放录像时间="+curDate);
	var playbackurl = "";
	var start_occur = start_occurTime(startTime);
	var end_occur = end_occurTime(endTime);	
	recordblock.setFdId(sbbh).setChannelId(tdbh).setHideTitle(tdmc).startPlayback(start_occur ,0,end_occur,playbackurl,sbbh,tdbh,0);
}
//关闭视频组件
function unloadWindow(){
	/*for(var i = 0;i < BlockCacher.blockCache.length;i++){
		if(BlockCacher.blockCache[i].fdId && BlockCacher.blockCache[i].channelId != null){
			BlockUtil.stopMonitor(i);
		}
	}*/
	if(videoblock && videoblock.fdId && videoblock.channelId != null){
		//实时视频关闭
		videoblock.stopMonitor();
		videoblock.setRunning(false).setHideTitle("").setTitle("")
		.setFdId("").setChannelId("").setMonId(null);
		videoblock.setPeerConnection(null);
		videoblock.getVideoComp().src = "";
	}
	if(recordblock && recordblock.fdId && recordblock.channelId != null){
		//录像关闭
		recordblock.stopPlayback();
		recordblock.setRunning(false).setHideTitle("").setTitle("")
		.setFdId("").setChannelId("").setMonId(null);
		recordblock.setPeerConnection(null);
		recordblock.getVideoComp().src = "";
	}
}
//关闭录像
function closeRecordvideo(){
	if(recordblock && recordblock.fdId && recordblock.channelId != null){
		//录像关闭
		recordblock.stopPlayback();
		recordblock.setRunning(false).setHideTitle("").setTitle("")
		.setFdId("").setChannelId("").setMonId(null);
		recordblock.setPeerConnection(null);
		recordblock.getVideoComp().src = "";
	}
}
//毫秒数转换
function timeChange(time){
	return Date.parse(new Date(time.replace(/-/g,"/")))/1000;
}
//事件开始事件，输入字符串时间前10秒
function start_occurTime(time){
	var dt=new Date(time.replace(/-/g,"/"));//将传入的日期格式的字符串转换为date
	var ndt=new Date(dt.getTime()-10000);//将转换之后的时间减去十秒
	//console.log('开始时间为：',ndt);
	return Date.parse(ndt)/1000;
}
//事件开始事件，输入字符串时间后10秒
function end_occurTime(time){
	var dt=new Date(time.replace(/-/g,"/"));//将传入的日期格式的字符串转换为date
	var ndt=new Date(dt.getTime()+10000);//将转换之后的时间减去十秒
	//console.log('结束时间为：',ndt);
	return Date.parse(ndt)/1000;
}
