def run():
    player = MyPlayer()
    if player is None:
        xbmclog('Kodi Hue: In run() could not instantiate player')
        return

    while not monitor.abortRequested():
        if len(hue.ambilight_controller.lights) and not ev.is_set():
            startReadOut = False
            vals = {}
            if player.playingvideo:  # only if there's actually video
                try:
                    vals = capture.getImage(200)
                    if len(vals) > 0 and player.playingvideo:
                        startReadOut = True
                    if startReadOut:
                        screen = image.Screenshot(capture.getImage())
                        hsv_ratios = screen.spectrum_hsv(
                            screen.pixels,
                            hue.settings.ambilight_threshold_value,
                            hue.settings.ambilight_threshold_saturation,
                            hue.settings.color_bias,
                            len(hue.ambilight_controller.lights))
                        for i in range(len(hue.ambilight_controller.lights)):
                            algorithm.transition_colorspace(
                                hue,
                                hue.ambilight_controller.lights.values()[i],
                                hsv_ratios[i],
                            )
                except ZeroDivisionError:
                    pass

        if monitor.waitForAbort(0.1):
            xbmclog('Kodi Hue: In run() deleting player')
            del player  # might help with slow exit.
def run():
    have_last = False
    last_ratios = []
    player = MyPlayer()
    if player is None:
        xbmclog('Kodi Hue: In run() could not instantiate player')
        return
    transition = ColourTransition()
    transition.launch(algorithm, mqttc)

    xbmclog('Kodi Hue: In run()')
    while not monitor.abortRequested():
        if not ev.is_set():
            startReadOut = False
            vals = {}
            if player.playingvideo:  # only if there's actually video
                transition.resume()
                try:
                    vals = capture.getImage(200)
                    if len(vals) > 0 and player.playingvideo:
                        startReadOut = True
                    if startReadOut:
                        screen = image.Screenshot(capture.getImage())
                        hsv_ratios = screen.spectrum_hsv(
                            screen.pixels,
                            hue.settings.ambilight_threshold_value,
                            hue.settings.ambilight_threshold_saturation,
                            hue.settings.color_bias,
                            1,
                            #                            len(hue.ambilight_controller.lights)
                        )
                        #h, s, v = hsv_ratios[0].hue(
                        #        True, hue.settings.ambilight_min, hue.settings.ambilight_max)
                        #algorithm.transition_rgb(last_ratios, have_last,
                        #        hsv_ratios[0], mqttc )
                        #last_ratios = [hsv_ratios[0].h, hsv_ratios[0].s, hsv_ratios[0].v]
                        #have_last = True
                        transition.transition(hsv_ratios)
                        xbmclog('Kodi Hue: HSV values')


#                        for i in range(len(hue.ambilight_controller.lights)):
#                            algorithm.transition_colorspace(
#                                hue, hue.ambilight_controller.lights.values()[i], hsv_ratios[i], )
                except ZeroDivisionError:
                    pass
        else:
            transition.pause()

        if monitor.waitForAbort(0.5):
            transition.stop()
            xbmclog('Kodi Hue: In run() deleting player')
            del player  # might help with slow exit.
    transition.waitThread()
    del transition
 def run(self):
     while not self.monitor.abortRequested():
         if len(self.ambilight_controller.lights) and not ev.is_set():
             startReadOut = False
             vals = {}
             if self.player.playingvideo:  # only if there's actually video
                 # ping metrics server to keep sessions alive while playing
                 # ping every 5 min
                 timeSinceLastPing = time.time() - self.lastMetricPing
                 if (timeSinceLastPing > 300):
                     self.lastMetricPing = time.time()
                     ga = GoogleAnalytics()
                     # Keep the session alive
                     ga.sendEventData("Playback", "Playing", "Video", None,
                                      1)
                 try:
                     pixels = capture.getImage(200)
                     if len(pixels) > 0:
                         screen = image.Screenshot(pixels)
                         hsv_ratios = screen.spectrum_hsv(
                             screen.pixels,
                             self.settings.ambilight_threshold_value,
                             self.settings.ambilight_threshold_saturation,
                             self.settings.color_variation,
                             self.settings.color_bias,
                             len(self.ambilight_controller.lights))
                         for i in range(
                                 len(self.ambilight_controller.lights)):
                             algorithm.transition_colorspace(
                                 self,
                                 self.ambilight_controller.lights.values()
                                 [i],
                                 hsv_ratios[i],
                             )
                 except ZeroDivisionError:
                     pass
         # Sleep for 0.1s
         if self.monitor.waitForAbort(
                 0.1 if self.player.playingvideo else 1):
             # Abort was requested while waiting. We should exit
             break