coreelec与安卓 双系统共存-默认CoreElec引导后10秒计时进入android插件

在把coreelec写入emmc后,默认打开coreelec,然后通过电源可以重启进入安卓。需要多点好多步骤,下面我通过自己制作的插件来实现开机倒计时默认进入安卓

  1. 首先需要打开设置服务里的允许本地控制,并且重启生效,
  2. 编写自动启动脚本 storage/.config/autostart.sh
    chmod +x autostart.sh
#!/bin/sh
(
    sleep 20  # 等待 Kodi 启动完成,可以根据需要调整等待时间
     
    /usr/bin/kodi-send --action="RunAddon(script.countdown)"
) &

  1. 制作插件在/storage/.kodi/建立新文件夹 script.countdown,并且放入两个文件
    addon.xml
<?xml version="1.0" encoding="UTF-8"?>
<addon id="script.countdown" name="Countdown" version="1.0.0" provider-name="Your Name">
    <extension point="xbmc.python.script" library="main.py">
        <provides>navigatescript</provides>
    </extension>
</addon>

main.py

import xbmcgui
import xbmc
import time
import subprocess
import threading
class CountdownThread(threading.Thread):
    def __init__(self, duration):
        super(CountdownThread, self).__init__()
        self.duration = duration
        self._stop_event = threading.Event()

    def run(self):
        for remaining in range(self.duration, 0, -1):
            if self.stopped():
                break
            self.show_notification(remaining)
            time.sleep(1)
        if not self.stopped():
            self.show_notification(0)
            restart_device()

    def stop(self):
        self._stop_event.set()

    def stopped(self):
        return self._stop_event.is_set()

    def show_notification(self, remaining):
        xbmcgui.Dialog().notification("重启安卓倒计时", f"剩余时间:{remaining} 秒")
def start_timer(duration):
    countdown_thread = CountdownThread(duration)
    countdown_thread.start()
    return countdown_thread

def stop_timer(countdown_thread):
    countdown_thread.stop()

# 执行外部命令的函数
def run_external_command(command):
    process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    output, error = process.communicate()
    return output.decode(), error.decode()
   
 
def restart_device():
    run_external_command("rebootfromnand")
    run_external_command("reboot -f")
    
    
 
if __name__ == '__main__':
        dialog = xbmcgui.Dialog()
        timer = start_timer(10)
        #dialog.ok("计时器", "计时已开始")
        dialog.yesno("计时器", "要停止计时吗?")
        stop_timer(timer)
  1. 重启打开插件,查看和激活启用countdown。可以运行一下看下效果。

四步都完成了就可以了,在coreElec 20.2-Nexus的X96 MAX+测试通过。应该问题不大。

插件测试挺顺利,ssh直接用MobaXterm_Personal_23.0 访问开了ssh的kodi,
后面开机指令的发送出了点问题,因为第一步本地服务里的本地控制没有打开,造成kodi-send始终不执行。所以四步完成,一个方便一点的双系统就成了。

整个过程的chat-gpt的提示下完成,后来google也没帮太大忙。运气
下载地址 http://pan.ezdial.cn/nasone/tvbox/script.countdown.zip
csdn下载地址https://download.csdn.net/download/wjcroom/88571782

------------------------截至以上已经完整-----------------------
稍后的调整:
今天看到了bard的升级,用bard.google.com生成了一个,kodi启动后自动运行插件的代码,免去了计时有时失效的问题。
大概是,

实例一:
新文件夹
/storage/.kodi/addons/script.module.myscript
在里面定义addon.xml

<addon id="script.module.myscript"
      version="1.0.0"
      provider-name="My Name">

  <requires>
    <import addon="xbmc.service"/>
  </requires>

  <extension point="xbmc.service">
    <service type="xbmc.service" id="script.module.myscript">
      <startonstartup enabled="true"/>
    </service>
  </extension>
</addon>

有可能需要建立这个文件
/storage/.kodi/addons/script.module.myscript/script.module.myscript.py

import xbmc

def on_start():
    # 每隔 1 秒钟,打印一条日志
    while True:
        xbmc.log("MyScript: Hello, world!")
        time.sleep(1)

if __name__ == "__main__":
    on_start()

这里的文件名很奇怪,可能因为
<service type="xbmc.service" id="script.module.myscript">
这里id的定义,就是这样要求的所以可能是需要这样
<extension point="xbmc.service" library="service/script.py" />

实例二,
新建目录:

/storage/.kodi/addons/sevice.myservice/

下面建立这样的两个文件
services/MyService.py 文件的示例:

Python

import xbmc

class MyService(xbmc.Service):

    def __init__(self):
        super().__init__()

    def onStart(self):
        # 执行一些启动操作

    def onStop(self):
        # 执行一些停止操作

addon.xml 文件的示例:

XML

<addon id="service.myservice"
      version="1.0.0"
      provider-name="My Name">

  <requires>
    <import addon="xbmc.service"/>
  </requires>

  <extension point="xbmc.service">
    <service type="xbmc.service" id="service.myservice">
      <startonstartup enabled="true"/>
    </service>
  </extension>
</addon>

同样还是觉得奇怪。

这样启动倒计时插件了。
https://kodi.wiki/view/List_of_built-in_functions#Add-on_built-in’s

import xbmc
xbmc.executebuiltin(“RunAddon(id)”)

https://kodi.wiki/view/Service_add-ons

Service add-ons

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="service.example"
       name="Example service"
       version="1.0.0"
       provider-name="">
  <requires>
    <import addon="xbmc.python" version="2.1.0"/>
  </requires>
  <extension point="xbmc.service" library="service.py" />
  <extension point="xbmc.addon.metadata">
    <platform>all</platform>
    <summary lang="en"></summary>
  </extension>
</addon>

If your add-on is meant to be run while Kodi is running, you need to periodically check if Kodi is exiting. The add-on is responsible for terminating when Kodi wants to exit. This can be checked by creating an xbmc.Monitor instance and calling the abortRequested() method. To wait for this event instead, call the waitForAbort() method.

Below is an example service that prints “hello addon!” every 10 seconds until Kodi exits:
翻译过来就是,kodi不退出,插件常驻后台,系统若是退出,waitForAbort(10)等10秒会有信号,也是暂停10秒的意思。若收到退出,就结束循环。收不到,就记录日志信息。
service.py

import time
import xbmc

if __name__ == '__main__':
    monitor = xbmc.Monitor()
    
    while not monitor.abortRequested():
        # Sleep/wait for abort for 10 seconds
        if monitor.waitForAbort(10):
            # Abort was requested while waiting. We should exit
            break
        xbmc.log("hello addon! %s" % time.time(), level=xbmc.LOGDEBUG)

其他类型的插件开发:
https://kodi.wiki/view/Add-on_development

经过一番不成熟的折腾,我把控件打包成开机自动运行的了。
以下是代码:
addon .xml

<addon id="script.example.countdown" version="1.0.0" name="Countdown" provider-name="Your Name">
    <requires>
         
        <import addon="script.module.web-pdb" version="1.6.2"/>
    </requires>
 
 <extension point="xbmc.python.script" library="main.py" >
        <provides>script.example.countdown</provides>
    </extension>
 <extension point="xbmc.service"  library="service.py" >
 <startonstartup enabled="true"/>
  </extension>

</addon>

service.py

import xbmc
import time
def on_start():
    # 每隔 1 秒钟,打印一条日志
    addon_id = "script.example.countdown"
    xbmc.executebuiltin("RunScript({})".format(addon_id)) 

if __name__ == "__main__":
    on_start()

main.py代码同上

实现开机自动启动倒计时提示。可以取消。
打包后的下载网址:
http://pan.ezdial.cn/nasone/kodi/script.example.countdown.zip

csdn下载
https://download.csdn.net/download/wjcroom/88608662
alist网盘dav
http://fa.ezdial.cn/
webdav
http://fa.ezdial.cn/dav
用户:1,密码:1
在kodi中,添加wedav配置以上内容。可以直接下载安装。

  • 6
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

wjcroom

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值