Switching relay during playback

  • Hello everybody,

    is it possible to query the current playback status?

    Background: I run Libreelec 11 on a Raspberry Pi in my children's room as an "audio player" for my daughter. I would like to switch on an amplifier as soon as the playback starts, and switch it off again shortly after the playback has ended. In terms of hardware, this is not a problem for me, but what about Libreelec? Is it possible to query the playback status (plugin?) and switch a GPIO to high or low accordingly?

    Thank you for your answers

  • Go to Best Answer
  • You can do this with Kodi's JSON-RPC API, it also supports notifications on playback start/end.

    JSON-RPC API - Official Kodi Wiki

    Make sure you have "Allow remote control from applications on this system" enabled in Kodi settings->Services->Control

    To test this functionality on LE you can use texturecache.py monitor - this will print the notifications sent by kodi. eg when playing a movie:

    Code
    LibreELEC:~ # texturecache.py monitor
    2023-07-25 12:47:13.082270: Playlist.OnAdd       : {"item": {"title": "H264_01_1080i_25-mobcal_ter.mkv", "type": "movie"}, "playlistid": 1, "position": 0}
    2023-07-25 12:47:13.132988: Player.OnPlay        : {"item": {"title": "H264_01_1080i_25-mobcal_ter.mkv", "type": "movie"}, "player": {"playerid": 1, "speed": 1}}
    2023-07-25 12:47:13.885345: Player.OnAVChange    : {"item": {"title": "H264_01_1080i_25-mobcal_ter.mkv", "type": "movie"}, "player": {"playerid": 1, "speed": 1}}
    2023-07-25 12:47:13.894253: Player.OnAVStart     : {"item": {"title": "H264_01_1080i_25-mobcal_ter.mkv", "type": "movie"}, "player": {"playerid": 1, "speed": 1}}
    2023-07-25 12:47:13.905896: Player.OnAVChange    : {"item": {"title": "H264_01_1080i_25-mobcal_ter.mkv", "type": "movie"}, "player": {"playerid": 1, "speed": 1}}
    2023-07-25 12:47:23.863005: VideoLibrary.OnUpdate: {"id": -1, "type": ""}
    2023-07-25 12:47:23.893663: Player.OnStop        : {"end": true, "item": {"title": "H264_01_1080i_25-mobcal_ter.mkv", "type": "movie"}}

    Have a look at /usr/bin/texturecache.py to see how that's implemented

    so long,

    Hias

  • You need something like Callbacks addon..

    You have many options in addon to choose from...you just need to run a small script on play media..

    Assuming your songs are in a folder called Music or Songs and you know how to connect relay etc this is all you need to run..

    something like this...

  • You can probably also set the calbacks addon to "on playback started" and on "playback stopped"