How to wait for media play to end
#1
Hi all,

I want to do the following.

I have 2 folders on the raspberry pi.
Folder one has all the songs i wanted to be on repeat.
Folder 2 has a song that is fired by a schedule at a given time.

So, for example, when the pi boots up, by default, it plays the songs in the default folder repeatedly using this command
xbmc.executebuiltin('xbmc.PlayMedia("default","isdir")')
xbmc.executebuiltin('xbmc.PlayerControl(RepeatAll)')

Now say i set the schedule to go off at 14:00.
It will play the song.

Now here is the question :
How do i set it up so that when the scheduled song has completed playing, i then proceed to play all the default songs as usual
Reply
#2
Okay. I have seen some snippets of code that have an event called "onPlayBackEnded".

I have tried to insert this code, but the event does not fire.

Has anyone used this before? If so, what do i need to do to get the event firing?

Thanks
Reply
#3
I've not heard of that handle. That doesn't mean it doesn't exist of course, but I wonder if the code snippet you found is calling something internal to the script called onPlayBakcEnded.

I use xbmc.Player().isPlayingAudio() to check and see if the player is playing an audio file. If it isn't, that will return False. Put the test in a loop (I recommend sleeping the loop for a second or two just so you don't hammer XBMC with requests) and you should be good to go.
Reply
#4
onPlayBackEnded is part of xbmc.Player().

You still need to keep the script alive in a loop (this works best in services), but you can do something like the following to run a function in your script when playback ends or is stopped

Code:
class Player_Instance(xbmc.Player):
    def __init__(self, *args, **kwargs):
        xbmc.Player.__init__(self)
        self.function_to_run = kwargs['function_to_run']

    def onPlayBackEnded(self):
        self.onPlayBackStopped()

    def onPlayBackStopped(self):
        self.function_to_run()

Then in the main part of your script, create your player and pass in the function with something along the lines of

Code:
self.Player = Player_Instance(function_to_run = self._a_function)

_a_function should then be run at the end of playback, where you could take care of choosing what to automatically play next.
Reply

Logout Mark Read Team Forum Stats Members Help
How to wait for media play to end0