@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 操作没反馈
下次再解决
1119

被折叠的 条评论
为什么被折叠?



