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:
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