海阔视界--vlc控制(3)

@TOC

改进想法

这两天刷小红书看难民,我都没时间写小程序了,唉,还是太懒惰了!现在继续!
上个小程序就播放可以用,其他都是摆设。现在要完成大部分按钮可用。一个一个写按钮太费事,所以要把小程序简化一下。好看不好看的以后再说,目标就是能用。
最后界面是这样的:
在这里插入图片描述

实现

要简化代码,就写一个新子页来放函数吧。
函数子页代码如下:

    const link = {
        play: '?command=in_play&input=$1',
        addlist: '?command=in_enqueue&input=$1',
        playid: '?command=pl_play&id=$1',
        playstop: '?command=pl_pause&id=$1',
        stop: '?command=pl_stop',
        playnext: '?command=pl_next',
        playpre: '?command=pl_previous',
        emptylist: '?command=pl_empty',
        fullscreen: '?command=fullscreen',
        vol: '?command=volume&val=$1',
        seek: '?command=seek&val=$1'
    }
    var link2 = ':8080/requests/status.xml'
    //给以后留个修改空间
    function 取源码(url, key) {
        let h = fetch(url, {
            headers: {
                'Authorization': 'Basic ' + key
            }
        })
        return h
    }
    //执行对应命令
    function cmd(str, a, key) {
        let ip = getMyVar('vlc_ip', '')
        if (ip == '') {
            return 'ip地址不能为空!'
        }
        let vurl = 'http://' + ip + link2 + link[str]
        if (vurl.includes('$1')) {
            vurl = vurl.replace('$1', a)
        }
        return 取源码(vurl, key)

    }
    //循环添加按钮
    function setbtn() {
        let btns = Object.keys(link)
        log(btns)
        for (let i = 0; i < btns.length; i++) {
            d.push({
                col_type: 'text_3',
                title: btns[i],
                url: $().lazyRule((btn,key) => {
                    require('hiker://page/函数')
                    let cmdval=link[btn]
                    let vurl = getMyVar('video_url', '')
                    let re = cmd(btn, vurl, key)
                    log(re)

                    return 'toast://开始播放!'
                }, btns[i],key)
            })
        }
        
    }
    

程序没啥说的都是基础玩意,然后首页程序改一下,调用子页中的代码。

js:
var ip = getMyVar('vlc_ip', '')
var key = 'OjEyMzEyMw==' //123123 vlc web密码

var d = []
d.push({
    col_type: 'input',
    title: 'ip地址',
    url: 'toast://填好就行,不用按!',
    extra: {
        defaultValue: getMyVar('vlc_ip', ''),
        onChange: "putMyVar('vlc_ip',input)"
    }
})
d.push({
    col_type: 'input',
    title: '播放',
    url: $.toString((key) => {
        let ip = getMyVar('vlc_ip', '')
        if (ip == '') {
            return 'toast://ip地址不能为空!'
        }
        //log(ip + input)
        ip = 'http://' + ip + ':8080/requests/status.xml?command=in_play&input=' + input
        //log(ip + input)
        let h = fetch(ip, {
            headers: {
                'Authorization': 'Basic ' + key
            }
        })
        //log(h)
        return 'toast://已经投送,请稍候!'
    }, key),
    extra: {
        defaultValue: getMyVar('video_url', ''),
        onChange: "putMyVar('video_url',input)"
    }

})
require('hiker://page/函数')
setbtn()

setResult(d)

可以运行了,播放,暂停,全屏啥的基本没问题了。

存在问题

1 音量调整,快进等功能还不行,按钮是批量添加的,这块没写操作逻辑。
2 添加播放列表有点麻烦
3 没处理任何错误
4 操作没反馈
下次再解决

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值