def _play_next_track(self, track=None, seek_value=0):
        if self.get_audio_player().is_stopping():
            logging.debug("asked to play next track when mplayer was still stopping")
            time.sleep(3) # hack!

        if track is None:
            track = self.get_next_track()
            seek_value = 0
        if track is None:
            self.on_empty_playlist()
        else:
            if not self.config().context.internet_detected:
                if track["url"][0:4] == "http":
                    inline_action("Sorry, the connection has been dropped.  Please hold.")
                    self.config().context.ignore_messages = False
                    return
            logging.debug("about to play next track...")
            # if self.get_mplayer().is_playing():
            #     logging.debug("mplayer is playing, quick load")
            #     self.get_mplayer().pause()
            self._say_track(track, seek_value)
                # self.get_mplayer().next_track(track["url"])
            # elif self.get_mplayer().is_stopped():
            #     logging.debug("mplayer is stopped, long load")
            #     self._say_track(track, seek_value)


            self.get_audio_player().start(track["url"], seek_value)
示例#2
0
 def on_previous_track_down(self):
     # say something
     if self.audio_player:
         self.audio_player.pause()
     saying = random.choice(self.state_config["phrases"])
     saying = saying.replace("%T",
                             datetime.datetime.now().strftime("%H:%M"))
     inline_action(saying)
     self.play_sleepy_music()
示例#3
0
 def on_enter(self):
     if self.state_config is not None:
         action = self.state_config["on_enter"]
     else:
         action = "Welcome, you are listening to {}".format(
             self.state_config["title"])
     inline_action(action)
     if self.thread_id is None:
         self._start_thread()
     else:
         self._resume_thread()
 def _say_track(self, track, seek_value):
     logging.debug("announcing track")
     what_to_call_track = "track"
     announce_seek_time = True
     if "announce-seek" in self.state_config:
         announce_seek_time = self.state_config["announce-seek"]
     if "word-for-track" in self.playlist_config:
         what_to_call_track = self.playlist_config["word-for-track"]
     if announce_seek_time == False or seek_value < 1:
         inline_action("Next {} is {}".format(what_to_call_track, track["name"]))
     else:
         time_string = self.app_state.voice_library.convert_seconds_to_saying(seek_value)
         inline_action("Next {} is {} starting at {}".format(what_to_call_track, track["name"], time_string))
示例#5
0
 def test_inline_action_4(self):
     #emits warning log
     self.assertFalse(
         actions.inline_action({
             "type": "sound",
             "wrong": "%SMARTBOT%/sounds/piano2.m4a"
         }))
示例#6
0
 def handle_reload_config(self, context):
     """
     Reload everything
     :return:
     """
     raise ValueError("this is wrong")
     inline_action(
         "I am reloading my activities, sorry for the inconvenience.")
     context.app_state.reload()
     new_states = context.personality().get_states()
     c_state_title = context._current_activity.title
     context._activity_objects = new_states
     if c_state_title:
         ev = Event(EventEnum.TRANSITION_TO_NAMED)
         ev.data = c_state_title
     else:
         ev = Event(EventEnum.TRANSITION_TO_FIRST)
     context.add_event(ev)
 def notify(self, event):
     super().notify(event)
     if event.id == EventEnum.DEVICE_RECONNECTED:
         self._restart_where_we_left_off()
     elif event.id == EventEnum.DEVICE_LOST:
         self.checkpoint(True)
         self.get_audio_player().stop()
     elif event.id == EventEnum.INTERNET_LOST:
         if self.current_track["url"][0:4] == "http":
             # looks as though when internet cuts out mplayer on pause can stay just fine.
             self.checkpoint(True)
             self.get_audio_player().pause()
             self.play_on_hold_until_internet_is_back = True
             inline_action("Sorry, the connection has been dropped.  Please hold.")
     elif event.id == EventEnum.INTERNET_FOUND:
         if self.current_track["url"][0:4] == "http":
             if self.play_on_hold_until_internet_is_back == True:
                 self.play_on_hold_until_internet_is_back = False
                 inline_action("Yay! The connection has been restored. Starting from where you left off.")
                 self._restart_where_we_left_off()
     elif event.id == EventEnum.ENTER_SLEEP_NOW:
         ## pause and stop immediately, without message to user
         self.on_previous_track_down()
示例#8
0
 def say_prompt(self):
     inline_action("Hi Innogen")
     self.say_time()
     inline_action(
         "I am currently waiting for something to do.  Use the play button to move to another activity."
     )
示例#9
0
 def say_time(self):
     saying = "The time is %T."
     saying = saying.replace("%T",
                             datetime.datetime.now().strftime("%H:%M"))
     inline_action(saying)
示例#10
0
 def on_empty(self):
     if "on_empty" in self.state_config:
         action = self.state_config["on_empty"]
     else:
         action = "There are no tracks available on this playlist."
     inline_action(action)
示例#11
0
 def on_previous_track_down(self):
     self.on_interrupt()
     inline_action("bye, see you later")
     ev = Event(EventEnum.TRANSITION_TO_NAMED)
     ev.data = self.state_config["on_end"]
     self.app_state.context.add_event(ev)
示例#12
0
 def do_work_in_thread(self, is_first_run):
     """Override"""
     logging.debug("working...")
     if self.device is None:
         try:
             self._find_input_device()
         except:
             pass
         if self.device is None:
             logging.debug("device not found yet, will try again in a bit")
             time.sleep(1)
             return
     if self.device_io is None:
         try:
             logging.debug("attempting to reopen device {}".format(
                 self.device))
             self.open()
             logging.debug("reconnected to virtual device")
         except:
             logging.debug("attempt failed, try again in a bit")
             self.device_io = None
             pass
     if self.device_io is None:
         time.sleep(1)
         return
     try:
         for ev in self.device_io.read_loop():
             if ev.code != 0:
                 logging.debug("device event detected " + repr(ev) + "," +
                               ecodes.KEY[ev.code])
                 new_event = None
                 if ev.code == 165:
                     if ev.value == 1:
                         new_event = Event(EventEnum.BUTTON_DOWN)
                         new_event.data = EVENT_BUTTON_PREV
                         inline_action({
                             "type": "sound",
                             "path": "%SMARTBOT%/sounds/beep.wav"
                         })
                     else:
                         new_event = Event(EventEnum.BUTTON_UP)
                         new_event.data = EVENT_BUTTON_PREV
                 if ev.code == 163:
                     if ev.value == 1:
                         new_event = Event(EventEnum.BUTTON_DOWN)
                         new_event.data = EVENT_BUTTON_NEXT
                         inline_action({
                             "type": "sound",
                             "path": "%SMARTBOT%/sounds/beep.wav"
                         })
                     else:
                         new_event = Event(EventEnum.BUTTON_UP)
                         new_event.data = EVENT_BUTTON_NEXT
                 if ev.code == 200:  # KEY_PLAYCD
                     if ev.value == 1:
                         new_event = Event(EventEnum.BUTTON_DOWN)
                         new_event.data = EVENT_BUTTON_PLAY
                         inline_action({
                             "type": "sound",
                             "path": "%SMARTBOT%/sounds/beep.wav"
                         })
                     # TM - we have removed this so we can detect skipping modes by multiple presses of play
                     # else:
                     #     new_event = Event(EventEnum.BUTTON_UP)
                     #     new_event.data = EVENT_BUTTON_PLAY;
                 if ev.code == 201:  # KEY_PAUSECD but we use it to change mode as well
                     if ev.value == 1:
                         new_event = Event(EventEnum.BUTTON_DOWN)
                         new_event.data = EVENT_BUTTON_PLAY
                         inline_action({
                             "type": "sound",
                             "path": "%SMARTBOT%/sounds/beep.wav"
                         })
                     # TM - we have removed this so we can detect skipping modes by multiple presses of play
                     # else:
                     #     new_event = Event(EventEnum.BUTTON_UP)
                     #     new_event.data = EVENT_BUTTON_PLAY;
                 if new_event is not None:
                     logging.debug("adding device event to queue")
                     self.context.add_event(new_event)
     except OSError as err:
         ## mostly likely we lost the device
         logging.debug(err)
         self.device_io = None
示例#13
0
 def test_inline_action_3(self):
     self.assertTrue(
         actions.inline_action({
             "type": "sound",
             "path": "%SMARTBOT%/sounds/piano2.m4a"
         }))
示例#14
0
 def test_inline_action_2(self):
     self.assertTrue(
         actions.inline_action({
             "type": "speech",
             "text": "hello two"
         }))
示例#15
0
 def test_inline_action(self):
     self.assertTrue(actions.inline_action("hello"))