//任务名
var taskName = 'a20200927csxgvideo';

//任务所有图片名
var picSrc =  [
    { src: 'loading.jpg' },
    { src: 'loading-numbg.png' },
    { src: 'share.jpg' },
    { src: 'ending.jpg' },
    { src: 'play.png' },
    { src: 'skip.png' }];//所有图片资源

//视频地址
var videoSrc= mediaURLData['7110'];//正式视频路径
// var videoSrc="https://mdup.apdcdn.tc.qq.com/vcloud1022.tc.qq.com/1022_072e7946db274a85a4f6038512643065.f0.mp4?vkey=FA4F1E222B11F2089085AF3036C9189047C9E7FF1374A68DFAF0D38716384345EB99D8BC993D0A42C3A5393A30A2B665CA0B209B635BD8B100A536317CC10A7C9AD32057351048FA87BC832BEB64987E1383892052A4E1E8&sha=0";//测试地址


$('body').on('touchmove',function(event){
    event.preventDefault();
});

//初始化视频组件
var videoPlayer=new MMD.VideoPlayer({
    videoElement:document.getElementById('video'),//[必填],video元素;
    src:videoSrc,//[必填],video src;
    loop:false,//[可选],是否循环,默认false,true为循环;
    muted:false,//[可选],是否静音,默认false,IOS下只有IOS10生效,安卓生效;
    poster:'',//[可选],video默认图片;
    tryMultipleVideoPlayAtTheSameTime:false,//[可选],尝试同时播放多个视频,默认false;
    timesParam:[
        {name:'Point1',time:10},
        {name:'Point2',time:20},
        {name:'Point3',time:30},
        {name:'Point4',time:40},
        {name:'Point5',time:50},
        {name:'Point6',time:60},
        {name:'Point7',time:70},
        {name:'Point8',time:80},
        {name:'Point9',time:90},
        {name:'Point10',time:100},
        {name:'Point11',time:110},
        {name:'Point12',time:120}
    ],//[可选],video currenttime时间点;
    onTimes:function(name){
        if(typeof name != "undefined"){
            var time = parseInt(name.substring(5),10) * 10;
            if(time == 10){
                showskip();
            }
            PTTSendClick('play','playtime-'+time,'播放了'+time+'10秒');
            EAS.SendClick({ e_c: 'act.'+taskName+'.video.playtime-'+time, c_t: 4 });
        }
    },//[可选],video currenttime回调;
    onStart:function(){
        PTTSendClick('btn','start','视频开始');
        PTTSendClick('play','start','视频开始');
        EAS.SendClick({ e_c: 'act.'+taskName+'.video.start', c_t: 4 })
        $(".load").fadeOut('slow');
    },//[可选],video第一个画面出现回调;
    onEnd:function(){
        hidevideo();
        PTTSendClick('btn','end','看完视频');
        PTTSendClick('play','end','看完视频');
        EAS.SendClick({ e_c: 'act.'+taskName+'.video.end', c_t: 4 })
    }//[可选],video播放完成回调;
});

//图片和视频预加载
preload(picSrc);

//预加载
function preload(picSrc) {
    preload = new createjs.LoadQueue(true, '//game.gtimg.cn/images/lol/act/'+taskName+'/');
    // 加载文件
    preload.loadManifest(picSrc);
    // 加载进度
    preload.on('fileprogress', function () {
        $("#load-num").html(Math.ceil(preload.progress * 100) + '%');
    })
    // 加载完成
    preload.on('complete', function () {
        var nowNum = parseInt($("#load-num").html().slice(0,-1));

        //防止加载完成时进度不为100%
        var nowNumArr=[nowNum,nowNum+4,nowNum+10,100];
        for(var i=0;i<nowNumArr.length;i++){
            if(nowNumArr[i]<=100){
                $("#load-num").html(nowNumArr[i] + "%");
            }
        }

        loadEnd();
        EAS.SendClick({e_c: 'act.'+taskName+'.load.succ', c_t: 4})
    })
}

//预加载结束事件。ios主动播放（掌盟不能自动播放），安卓需要用户交互再播放。
//ios自动播放，视频过大会出现进度条100%之后长时间不播放
function loadEnd() {
    if(videoPlayer.isVideoCanAutoPlay){
        videoPlayer.play();
    } else {
        $('#load-enter').fadeIn('slow');
        $('#page-load').bind('click',function(e) {
            $('#load-enter').fadeOut('slow');
            $("#load-num").fadeOut('slow');
            $("#page-load").addClass('slowShow');
            videoPlayer.play();
        })
    }
}

//视频播放完成后显示落版页;
function hidevideo(){
    $("#parent").fadeOut();
    $("#skip").hide();
    $(".end").show().removeClass("disable");
    PTTSendClick('btn','endpage','落版页');
    EAS.SendClick({e_c:'act.'+taskName+'.page.endpage',c_t:4});
}

//跳过按钮的显示;
function showskip(){
    $("#skip").fadeIn();
}

//跳过按钮点击显示落版页
function endpage() {
    $("#skip").fadeOut();
    $("#parent").hide();
    $(".end").fadeIn().removeClass("disable");
    PTTSendClick('btn','endpage','落版页');
    EAS.SendClick({e_c:'act.'+taskName+'.page.endpage',c_t:4});
}

//跳过按钮点击事件
$("#skip").on("click",function(){
    endpage();
    videoPlayer.pause();
    PTTSendClick('btn','skip','跳过');
    EAS.SendClick({e_c:'act.'+taskName+'.video.skip',c_t:4});
});

//再看一次
function watchAgain() {
    $(".end").fadeOut();
    $("#parent").fadeIn();
    videoPlayer.replay();
    PTTSendClick('btn','replay','再看一次');
    EAS.SendClick({e_c:'act.'+taskName+'.video.replay',c_t:4});
}

//页面跳转点击事件
function openurl(urlTask){
    PTTSendClick('btn',urlTask,'进入官网');
    EAS.SendClick({e_c:'act.'+taskName+'.go.'+urlTask,c_t:4});
}
