var player = null,
playing = false,
setval = null;
var u = navigator.userAgent;
var x5_type = 'h5';
if (/(iPhone|iPad|iPod|iOS)/i.test(u)) { //判断iPhone|iPad|iPod|iOS
x5_type = 'h5';
} else if (/(Android)/i.test(u)) { //判断Android
x5_type = 'h5-page';
}
var clientHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
var clientWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
$(function(){
// 直播
livePlay();
// 点播
playered();
xjhjobList(xjhid,1,1);
$('.chat_nav li>a').each(function() {
$(this).click(function() {
$('.chat_nav li>a').removeClass("show_box_menu_border");
$(this).addClass("show_box_menu_border");
})
var ah2 = document.querySelectorAll(".chat_nav li>a")
var ap = document.querySelectorAll(".show_box_menu_con>div")
// 遍历元素
//这里我们要通过for循环去获取li中的索引,然后成功的运用到下面的div中。
for (var i = 0; i < ah2.length; i++) {
// 编号
ah2[i].index = i;
// 各种事件
ah2[i].onclick = function() {
for (var j = 0; j < ap.length; j++) {
ap[j].style.display = "none"
}
// 显示
if(ap[this.index]){
ap[this.index].style.display = "block";
}
}
}
})
//用户变化屏幕方向时调用
$(window).bind('orientationchange', function() {
if(playing){
palyOrient();
}else{
orient();
}
});
})
function livePlay() {
if (document.getElementById('live_video')) {
var live_hls = document.getElementById('live_hls').value,
live_poster = document.getElementById('live_poster').value,
img = $("#poster").find('img').attr('src'),
poster = img ? img : live_poster;
player = new TcPlayer('live_video', {
"m3u8": live_hls,
"autoplay": true,
"live": true,
"poster": poster,
//"width": '640',
"height": '220',
"x5_player": true,
"x5_type": x5_type,
"x5_orientation": 0,
//"x5_playsinline": 1,
"x5_fullscreen": true, //是否全屏
"wording": {
1: "网络错误,请检查网络配置",
4: "主持人暂时离开,请稍候片刻",
},
"listener": function(msg) {
if (msg.type == 'playing') {
playing = true;
} else if (msg.type == 'pause' || msg.type == 'ended' || msg.type == 'error') {
playing = false;
}
}
});
}
}
function playered() {
if (document.getElementById('playered')) {
var url = $("#playurl").val();
// 实例化播放器
player = new QPlayer({
url: url,
container: document.getElementById("playered"),
autoplay: true,
loggerLevel: 3,
defaultViewConfig: {
settingsIcon: mbstyle +'/images/qiniuset.png'
}
});
player.on('play', function() {
//用户变化屏幕方向时调用
$(window).bind('orientationchange', function() {
palyOrient();
});
});
}
}
// 播放时处理横屏和竖屏
function palyOrient() {
if(typeof commonHide != 'undefined'){
commonHide();
}
if (window.orientation == 90 || window.orientation == -90) {
//横屏
// 直播
if ($("#live_video").length > 0) {
$("#liveTab").hide();
player.fullscreen(true);
}
return false;
} else if (window.orientation == 0 || window.orientation == 180) {
//竖屏
// 直播
if ($("#live_video").length > 0) {
$("#liveTab").show();
player.fullscreen(false);
$(window).unbind();
orient();
}
return false;
}
}
// 处理横屏和竖屏
function orient() {
if(typeof commonHide != 'undefined'){
commonHide();
}
if (window.orientation == 90 || window.orientation == -90) {
//横屏
// 直播
if ($("#live_video").length > 0) {
$("#liveTab").hide();
$(".e_resume").hide();
setTimeout(function(){
var clientHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
var hpheight = clientHeight - 51 + 'px';
$("#livebody").css('height',hpheight);
$("#xjhdiv").attr('style','width:60%;margin:0 auto;');
$(".vcp-player").css({"width":"100%","height":hpheight});
$("#live_video").find('video').css({"width":"100%","height":hpheight});
$('.xjh_show_wid').css({"width":"60%","margin":"0 auto"});
$(".show_box_chat_input").css({"width":"60%","margin":"0 auto","background":"#fff","box-shadow":"none"});
},200)
}
} else if (window.orientation == 0 || window.orientation == 180) {
//竖屏
// 直播
if ($("#live_video").length > 0) {
$("#liveTab").show();
$(".e_resume").show();
$("#livebody").css('height','220px');
$(".vcp-player").css({"width":"100%","height":'220px'});
$("#live_video").find('video').css({"width":"100%","height":'220px'});
$("#xjhdiv").removeAttr('style');
$('.xjh_show_wid').removeAttr('style');
$(".show_box_chat_input").removeAttr('style');
}
return false;
}
}
if(livestatus == 1){
var serverTime = new Date().getTime(),
djsTimer = null;
// 监测浏览器息屏和可见
var hiddenProperty = 'hidden' in document ? 'hidden' : 'webkitHidden' in document ? 'webkitHidden' : 'mozHidden' in document ? 'mozHidden' : null;
// 不同浏览器的事件名
var visibilityChangeEvent = hiddenProperty.replace(/hidden/i, 'visibilitychange');
var onVisibilityChange = function(){
var nowTime = new Date().getTime();
if(!document[hiddenProperty]){
if(serverTime > 0 && (nowTime - serverTime > 60000)){
clearTimeout(djsTimer);
serverTime = nowTime;
liveUtil();
}
}else{
serverTime = nowTime;
if(player){
player.pause();
}
}
}
document.addEventListener(visibilityChangeEvent, onVisibilityChange);
// 处理倒计时
liveUtil();
}
function liveUtil(){
var stime = parseInt($("#live_stime").val()) * 1000;
var time = stime -serverTime;
if (serverTime < stime) {
var vm = new Vue({
el: '#waitshow',
data: {
time:time,
},
methods: {
onFinish() {
$('#waitshow').hide();
$('.sp_img').hide();
$('.number').show();
//倒计时结束
if (!document.getElementById('live_video')) {
$('#livediv').append('