Handling "OpenInputStream - error opening" programmatically
#1
Hi,

how can I handle such xbmc.Player().play(url) errors programmatically?

I already tried:

Code:
class MyPlayer(xbmc.Player):
    def __init__( self, *args, **kwargs ):
        xbmc.Player.__init__( self )
        
    def PlayStream(self, url):  
        self.play(url)            
        while self.isPlaying():
            xbmc.sleep(1000)
        
    def onPlayBackEnded( self ):
        notify("ended", "ended")
      
    def onPlayBackStopped ( self ):
        notify("stopped", "stopped")

... but none of this events are fired in this case of error Undecided

cheerz, lorus
Reply
#2
Set a total runtime property on your class. In your init, set it to something unique like 9999. In your while loop, check the total run time and set the property to the actual run time. In OnPlaybackEnded, check the property. If it's still 9999, you know it failed silently and can raise an error
Reply
#3
(2013-04-15, 15:56)Bstrdsmkr Wrote: Set a total runtime property on your class. In your init, set it to something unique like 9999. In your while loop, check the total run time and set the property to the actual run time. In OnPlaybackEnded, check the property. If it's still 9999, you know it failed silently and can raise an error

Sorry but I don't understand your approach ... OnPlaybackEnded doesn't fires in the error case ... so how should that work out?
Reply
#4
Solved it now in this way:

Code:
    xbmc.Player().play(url)
    xbmc.sleep(500)
    if not xbmc.Player().isPlaying():
        notify("error", "error")
Reply
#5
Sorry, I was on my phone earlier. I had to handle the same problem myself and the problem I ran into with your method is that sometimes isPlaying() will report false for a bit even though it is playing

Here's the code I used, hope it helps:
Code:
class Player(xbmc.Player):

    def __init__(self):
        xbmc.Player.__init__(self)
        self._totalTime = 999999
        self._lastPos = 0

    def onPlayBackStarted(self):
        self._totalTime = self.getTotalTime()
        while not xbmc.abortRequested and self.isPlaying():
            self._lastPos = self.getTime()
            xbmc.sleep(500)

    def onPlayBackStopped(self):
        playedTime = int(self._lastPos)
        if playedTime == 0 and self._totalTime == 999999:
            raise PlaybackFailed('XBMC silently failed to start playback')
Reply
#6
(2013-04-16, 01:12)Bstrdsmkr Wrote: Sorry, I was on my phone earlier. I had to handle the same problem myself and the problem I ran into with your method is that sometimes isPlaying() will report false for a bit even though it is playing

Here's the code I used, hope it helps:
Code:
class Player(xbmc.Player):

    def __init__(self):
        xbmc.Player.__init__(self)
        self._totalTime = 999999
        self._lastPos = 0

    def onPlayBackStarted(self):
        self._totalTime = self.getTotalTime()
        while not xbmc.abortRequested and self.isPlaying():
            self._lastPos = self.getTime()
            xbmc.sleep(500)

    def onPlayBackStopped(self):
        playedTime = int(self._lastPos)
        if playedTime == 0 and self._totalTime == 999999:
            raise PlaybackFailed('XBMC silently failed to start playback')

thanks, but as I said before onPlayBackStopped() never triggers in my error case ...
Reply

Logout Mark Read Team Forum Stats Members Help
Handling "OpenInputStream - error opening" programmatically0