2023-07-07, 00:22
Hi,
I am writing an addon for a local TV broadcaster and they require a keepalive request every now and then, otherwise the manifest URL expires. Keepalive is only necessary if the player isn't actively playing content as long as chunks are requested, not even their web app sends keepalives.
So I want to send keepalive requests only if the user pauses the playback + if the playback gets stopped, I want to send a teardown request.
For that I read a couple of methods. I have seen some existing addons checking on the player in a loop right inside their playback initiating method. This has the benefit that I already have some context (media id and I can assume that the playback belongs to my addon).
But I have also seen solutions involving background services and threads. Not sure if I need that or not.
I have cooked up some example here: eqaboduxic (paste) It's very far from working, but it should give you an idea of what I am trying to do. Right now, the line where I put the "if kodi isn't playing any file" comment is necessary, since it can happen that kodi isnt playing any file anymore. Not sure why. And the pause handler isn't getting executed as the self.player.getPlayingFile().startswith("plugin://plugin.video.addonname/") never gets executed. Seemingly that contains the actual URL for the stream. It's a random CDN URL therefore I can't rely on the startswith method. Is there any other way to check if the playback is from my addon?
Also, the teardown call never gets executed now either. I am not really sure why.
I am not begging for spoonfeeding, but I am struggling to get it working. If you could at least direct me to the right way by providing an existing addon source that does something similar properly, I would already be grateful.
Thanks
I am writing an addon for a local TV broadcaster and they require a keepalive request every now and then, otherwise the manifest URL expires. Keepalive is only necessary if the player isn't actively playing content as long as chunks are requested, not even their web app sends keepalives.
So I want to send keepalive requests only if the user pauses the playback + if the playback gets stopped, I want to send a teardown request.
For that I read a couple of methods. I have seen some existing addons checking on the player in a loop right inside their playback initiating method. This has the benefit that I already have some context (media id and I can assume that the playback belongs to my addon).
But I have also seen solutions involving background services and threads. Not sure if I need that or not.
I have cooked up some example here: eqaboduxic (paste) It's very far from working, but it should give you an idea of what I am trying to do. Right now, the line where I put the "if kodi isn't playing any file" comment is necessary, since it can happen that kodi isnt playing any file anymore. Not sure why. And the pause handler isn't getting executed as the self.player.getPlayingFile().startswith("plugin://plugin.video.addonname/") never gets executed. Seemingly that contains the actual URL for the stream. It's a random CDN URL therefore I can't rely on the startswith method. Is there any other way to check if the playback is from my addon?
Also, the teardown call never gets executed now either. I am not really sure why.
I am not begging for spoonfeeding, but I am struggling to get it working. If you could at least direct me to the right way by providing an existing addon source that does something similar properly, I would already be grateful.
Thanks