如何用JS控制多个视频的连续播放

JavaScript09

如何用JS控制多个视频的连续播放,第1张

window.onload=function(){

var str = '${vedioStr}' //所要播放视频的路径组

var strList = str.split("X") //要循序播放的路径组字符串转换成路径数组

var i=0

var len = strList.length

if( strList[i] != null &&strList[i]!='' &&strList[i] !='null'){

$("#XX").find("OBJECT").attr("filename", strList[i])//设置视频路径为第一个路径组路径

}

window.setInterval(function(){ //每过0.5秒监控一下视频是否正在播放,如果没在播放则顺序播放下一个视频

if($("#XX").find("OBJECT").attr("playState")==0){//判断视频的播放状态不同player状态不同

i++//处理播放顺序和for循环处理差不错

if(i==len){

i=0

}

if( strList[i] != null &&strList[i]!='' &&strList[i] !='null'){

$("#XX").find("OBJECT").attr("filename", strList[i]) //如果当前播放完毕则播放下一个

}

}

}, 500) //每个0.5秒监控一下

}

/**

 * 3元起提,没有限制,只要求手机验证码 

 */

const perVideoWatchTime=8//每隔视频观看10秒

const halfDeviceHeight=device.height/2

const halfDeviceWidth=device.width/2

const videoSwipeDistance=halfDeviceHeight-100//视频下滑的长度 px

// test()

onlyRun()

//只允许本脚本时,将上行解除注释

function onlyRun(){

    auto()

    console.show()

    log("开始快手极速版")

    images.requestScreenCapture(false)

    log("已获得截屏权限") 

    let totalTime=2*60*60 //刷2小时

    run(totalTime)

}

function test(){

    auto()

    console.show()

    log("开始快手极速测试")

    images.requestScreenCapture(false)

    log("已获得截屏权限") 

    click("我知道了")

    exit()

}

var kuaiShou = {}

kuaiShou.main = function (totalTime) {    

    run(totalTime)

  }

module.exports = kuaiShou

function run(totalTime){

    log("计划时长:"+totalTime)

    //启动快手极速版

    launchApp()

    let watchTime=0

    for(let i=1totalTime>watchTimei++){

        if(text("拖动滑块").findOnce()){

            log("出现验证码,结束")

            runOver()

            break

        }

        let waitTime=perVideoWatchTime+random(-4,4)

        log("本视频观看时长"+waitTime)

        sleep(waitTime/2*1000)

        likeAndfollow(7)

        sleep(waitTime/2*1000)

        watchTime+=waitTime

        log("已看:"+i+"个视频 "+watchTime+"秒")

        swipeVideo(i)

    }

}

function launchApp(){

    let isLauchApp=false

    while(!isLauchApp){

        log("尝试启动")

        launchPackage("com.kuaishou.nebula")

        sleep(10000)        

        let mesbox=id("com.kuaishou.nebula:id/a4v").findOnce()

        if(mesbox){

            mesbox.click()

        }

        mesbox=id("com.kuaishou.nebula:id/close").findOnce()

        if(mesbox){

            mesbox.click()

        }

        mesbox=text("我知道了").findOnce()

        if(mesbox){

            mesbox.click()

        }

        isLauchApp=id("com.kuaishou.nebula:id/circular_progress_bar").findOnce()

    }

    log("已启动")

}

//swipeCount,滑动视频的次数

function swipeVideo(swipeCount){

    let offset=random(-100,0)

    if(swipeCount%6==0){

        //  双数的第6次下滑

        swipe(halfDeviceWidth-random(-50,50), halfDeviceHeight+offset+(videoSwipeDistance/2), 

        halfDeviceWidth+random(-50,50), halfDeviceHeight+offset-(videoSwipeDistance/2), 30)

    }else if(swipeCount%2==0){

        //双数次上滑        

        swipe(halfDeviceWidth+random(-50,50), halfDeviceHeight+offset, 

        halfDeviceWidth+random(-50,50), halfDeviceHeight+offset+(videoSwipeDistance/2), 30)

    }else {

        //单数下滑

        swipe(halfDeviceWidth-random(-50,50), halfDeviceHeight+offset+(videoSwipeDistance/2), 

        halfDeviceWidth+random(-50,50), halfDeviceHeight+offset-(videoSwipeDistance/2), 30)

    }

}

//有range*2+1分之一的概率点喜欢,range*4+1分之一的概率点关注,关注必定喜欢

function likeAndfollow(range){

    let isLike=random(-1*range,range)

    if(isLike==0){

        if(id('com.kuaishou.nebula:id/like_icon').findOnce()){

            var ddd = id('com.kuaishou.nebula:id/like_icon').findOne().bounds()

            click(1000,1300)

            sleep(1000)

        }

        else{

            log('不存在')

        }

        // click(halfDeviceWidth,halfDeviceHeight)

        // sleep(50)

        // click(halfDeviceWidth,halfDeviceHeight)

        let isFollow=random(-1*range,range)

        if(isFollow==0){

            text("关注").click()

            log("点了关注")

        }else{

            log("不是点关注的概率:"+isFollow)

        }

    }else{

        log("不是点喜欢的概率:"+isLike)

    }

}

//是否已经不再有收益了

function isNoIncome(){

    let isIncome=findIncomeIcon()

    if(!isIncome){

        sleep(6000)

        isIncome=findIncomeIcon()

        if(!isIncome){

            log("等待6秒,不见收益红包")

            return false

        }

    }

    log("正在收益中")

    return true

}

//查找收入红包的图标,是收益中的返回true 否则返回false

function findIncomeIcon(){

    let redBag=id(" com.kuaishou.nebula:id/circular_progress_bar").findOnce()

    if(redBag){

        let redBagBounds=redBag.bounds()

        let screen=images.captureScreen()

        // log(redBagBounds)

        let p=images.findColorEquals(screen,"#f85050",redBagBounds.left,redBagBounds.top,redBagBounds.width(),redBagBounds.height())

        return p?true:false

    }

    return false

}

function runOver(){

    home()

}

FLV.js视频播放重复的原因可能是由于视频的编码格式不一致或者视频的缓冲时间不够导致的。此外,视频的播放器也可能存在问题,比如播放器的版本过低或者播放器的设置不当等等。因此,如果您想解决FLV.js视频播放重复的问题,您可以尝试检查视频的编码格式,确保视频的缓冲时间足够,并且检查播放器的版本和设置,以确保播放器能够正常工作。