Esempio n. 1
0
    def checkPlayBackStarted(self, startup=False):
        if hasattr(self, 'playing') and self.playing:
            return

        for x in range(3):  # retry 2 times before giving up
            try:
                j = utilxbmc.xjson({
                    "jsonrpc": "2.0",
                    "method": "Player.GetActivePlayers",
                    "id": 1
                })
                t = j[0]['type']
                i = j[0]['playerid']
                log("onPlayBackStarted: t=%s, i=%s" % (t, i))
                if t == 'video':
                    j = utilxbmc.xjson({
                        "jsonrpc": "2.0",
                        "method": "Player.GetItem",
                        "params": {
                            "playerid": i
                        },
                        "id": 1
                    })
                    type = j['item']['type']
                    log("onPlayBackStarted: type=%s" % type)
                    if type == 'movie':
                        self.playing = Movie()
                        self.__time()
                    elif type == 'episode':
                        self.playing = Episode()
                        self.__time()
            except (IndexError, TypeError):
                if not startup:
                    log(
                        "onPlayBackStarted: Can't retrieve active player status, retrying.. %d"
                        % x, xbmc.LOGWARNING)
                    if monitor.waitForAbort(1):
                        break
                    if x < 2:
                        continue
                    else:
                        log(
                            "onPlayBackStarted: Could not get player info, giving up!",
                            xbmc.LOGERROR)
                self.playing = None
            except Exception:
                self.playing = None
                if debug.get():
                    log(debug.traceback.print_exc(), xbmc.LOGERROR)
                return
            break