示例#1
0
    def handle_id(self, message):
        if message['id'] == Utils.id_cover_loaded:
            Clock.schedule_once(partial(self.listener.on_cover_loaded, message['result']), -1)
        elif message['id'] == Utils.id_tracklist_loaded:
            Clock.schedule_once(partial(self.listener.tracklist_changed, message['result']), -1)
        elif message['id'] == Utils.id_current_track_loaded:
            self.listener.current_tl_track = message['result']
            Clock.schedule_once(partial(self.listener.track_playback_started, message['result']), -1)
            self.send(Utils.get_message(Utils.id_current_time_position_loaded, 'core.playback.get_time_position'))
        elif message['id'] == Utils.id_current_time_position_loaded:
            Clock.schedule_once(partial(self.listener.seeked, message['result']), -1)
            self.time_position = message['result']
            self.send(Utils.get_message(Utils.id_current_status_loaded, 'core.playback.get_state'))
        elif message['id'] == Utils.id_current_status_loaded:
            print message['result']
            if message['result'] == PlaybackState.PAUSED:
                print "paudes"
                Clock.schedule_once(partial(self.listener.track_playback_paused, self.listener.current_tl_track, self.time_position), 0.2)
            elif message['result'] == PlaybackState.STOPPED:
                Clock.schedule_once(partial(self.listener.track_playback_ended, self.listener.current_tl_track, self.time_position), 0.2)
            else:
                print "play"
                Clock.schedule_once(partial(self.listener.track_playback_resumed, self.listener.current_tl_track, self.time_position), 0.2)

        elif message['id'] == Utils.id_search_result or message['id'] == Utils.id_browse_loaded:
            Clock.schedule_once(partial(self.listener.result_loaded, message['result'], message['id']), -1)
        elif message['id'] == Utils.id_playlists_loaded:
            Clock.schedule_once(partial(self.listener.playlists_loaded, message['result']), -1)
示例#2
0
 def track_playback_started(self, tl_track):
     try:
         self.ids.title.text = Utils.get_title_string(tl_track)
         self.ids.album.text = Utils.get_album_string(tl_track)
         self.ids.artist.text = Utils.get_artist_string(tl_track)
     except Exception as e:
         print(str(e))
 def track_playback_ended(self, tl_track, time_position):
     self.set_playing(False)
     if self.timer is not None:
         Clock.unschedule(self.timer)
     self.timer = None
     self.ids.slider.value = 0
     self.ids.current_pos.text = Utils.format_time_to_string(0)
     self.ids.duration.text = Utils.format_time_to_string(0)
示例#4
0
 def track_playback_ended(self, tl_track, time_position):
     self.set_playing(False)
     if self.timer is not None:
         Clock.unschedule(self.timer)
     self.timer = None
     self.ids.slider.value = 0
     self.ids.current_pos.text = Utils.format_time_to_string(0)
     self.ids.duration.text = Utils.format_time_to_string(0)
示例#5
0
 def on_selection_change(self, adapter):
     if len(adapter.selection) > 0:
         data = adapter.data[adapter.selection[0].index]
         tlid = data['tlid']
         self.ws.send(
             Utils.get_message(0, 'core.playback.play', {'tlid': tlid}))
         name = data['track']['name']
         Utils.speak('PLAY_URI', val=name)
 def on_selection_change(self, adapter):
     if len(self.adapter.selection) > 0:
         data = []
         data.extend(adapter.data)
         data.insert(0, data.pop(adapter.selection[0].index))
         self.ws.send(Utils.get_message(0, "core.tracklist.clear"))
         self.ws.send(Utils.get_message(0, "core.tracklist.add", {"tracks": data}))
         self.ws.send(Utils.get_message(0, "core.playback.play"))
         self.adapter.selection = []
示例#7
0
 def go_up(self):
     if len(self.current_dir) == 1:
         Utils.speak('CH')
         self.main_screen.go_to_screen('Odtwarzacz')
     else:
         Utils.speak('GO_UP_DIR')
         self.current_dir.pop()
         uri = self.current_dir[-1]
         self.browse(uri)
示例#8
0
 def track_playback_started(self, tl_track, td):
     self.current_tl_track = tl_track
     self.load_cover(tl_track)
     for screen in self.ids.screen_manager.screens:
         screen.track_playback_started(tl_track)
     if tl_track is not None:
         try:
             Utils.speak('PLAYING', val=tl_track['track']['name'])
         except Exception as e:
             print(str(e))
示例#9
0
 def prev_item(self):
     self.clear_list_item_selection()
     if self.current_item == 0:
         self.current_item = len(self.adapter.data) - 1
     else:
         self.current_item = self.current_item - 1
     view = self.adapter.get_view(self.current_item)
     if view is not None:
         self.adapter.select_item_view(view)
         Utils.speak_text(Utils.convert_text(view.text))
         # scrolling
         selected_index = self.adapter.selection[0].index
         if selected_index > 4:
             self.ids.list_view.scroll_to(selected_index - 4)
         else:
             self.ids.list_view.scroll_to(0)
示例#10
0
    def track_playback_started(self, tl_track):
        if tl_track is not None:
            self.set_playing(True)
            # Load the data in the next screen
            # self.ids.screen_manager.get_screen(
            #     self.ids.screen_manager.next()
            #     ).track_playback_started(tl_track)
            # self.ids.screen_manager.transition.direction = 'left'
            #
            # # Move to the next screen
            # self.ids.screen_manager.current = self.ids.screen_manager.next()

            if 'length' in tl_track['track']:
                self.has_duration = True
                duration = int(tl_track['track']['length'] / 1000)
            else:
                self.has_duration = False
                duration = 0
            self.ids.slider.max = duration
            self.ids.slider.value = 0
            self.ids.duration.text = Utils.format_time_to_string(duration)
            if self.timer is None and self.has_duration:
                self.timer = Clock.schedule_interval(self.update, 0.1)
        else:
            self.track_playback_ended(None, 0)
示例#11
0
 def track_playback_resumed(self, tl_track, time_position):
     self.set_playing(True)
     self.ids.slider.value = time_position / 1000
     self.ids.current_pos.text = Utils.format_time_to_string(time_position /
                                                             1000)
     if self.timer is None and self.has_duration:
         self.timer = Clock.schedule_interval(self.update, 0.1)
示例#12
0
 def start_data(self):
     self.ws.send(
         Utils.get_message(
             Utils.id_tracklist_loaded, 'core.tracklist.get_tl_tracks'))
     self.ws.send(
         Utils.get_message(
             Utils.id_current_track_loaded,
             'core.playback.get_current_tl_track'))
     self.ws.send(
         Utils.get_message(
             Utils.id_playlists_loaded, 'core.playlists.as_list'))
     self.ws.send(
         Utils.get_message(
             Utils.id_browse_loaded, "core.library.browse", {'uri': None}))
     self.ws.send(
         Utils.get_message(
             Utils.id_volume, "core.mixer.get_volume"))
 def __init__(self, ws,  **kwargs):
     super(BaseListScreen, self).__init__(ws, **kwargs)
     args_converter = lambda row_index, x: {'text': Utils.get_title_string(x), 'size_hint_y': None,
         'height': 45}
     self.adapter = ListAdapter(data=[], cls=MopidyListItem, args_converter=args_converter)
     self.adapter.selection_mode = 'single'
     self.ids.list_view.adapter = self.adapter
     self.adapter.bind(on_selection_change=self.on_selection_change)
示例#14
0
 def load_cover(self, tl_track):
     if tl_track is not None:
         try:
             params = {'uris': [tl_track['track']['uri']]}
             self.ws.send(
                 Utils.get_message(
                     Utils.id_cover_loaded,
                     'core.library.get_images', params))
         except Exception as e:
             print(str(e))
示例#15
0
    def next_item(self):
        self.clear_list_item_selection()
        if len(self.adapter.data) == self.current_item + 1:
            self.current_item = 0
        else:
            self.current_item = self.current_item + 1
        view = self.ids.list_view.adapter.get_view(self.current_item)
        self.ids.list_view.adapter.select_item_view(view)
        # scrolling
        selected_index = self.adapter.selection[0].index
        if selected_index > 4:
            self.ids.list_view.scroll_to(selected_index - 4)
        else:
            self.ids.list_view.scroll_to(0)

        if view.text == '../':
            Utils.speak('UP_DIR')
        else:
            Utils.speak_text(Utils.convert_text(view.text))
示例#16
0
 def handle_event(self, message):
     if message['event'] == "track_playback_started":
         Clock.schedule_once(partial(self.listener.track_playback_started, message['tl_track']), 0.2)
     elif message['event'] == "track_playback_paused":
         Clock.schedule_once(partial(self.listener.track_playback_paused, message['tl_track'], message['time_position']), 0.2)
     elif message['event'] == "track_playback_resumed":
         Clock.schedule_once(partial(self.listener.track_playback_resumed, message['tl_track'], message['time_position']), 0.2)
     elif message['event'] == "track_playback_ended":
         Clock.schedule_once(partial(self.listener.track_playback_ended, message['tl_track'], message['time_position']), -1)
     elif message['event'] == "seeked":
         Clock.schedule_once(partial(self.listener.seeked, message['time_position']), -1)
     elif message['event'] == "tracklist_changed":
         self.send(Utils.get_message(Utils.id_tracklist_loaded, 'core.tracklist.get_tl_tracks'))
示例#17
0
 def go_uri(self, data):
     self.current_dir.append(data['uri'])
     self.browse(data['uri'])
     if data['type'] == 'track':
         self.ws.send(Utils.get_message(0, "core.tracklist.clear"))
         self.ws.send(
             Utils.get_message(0, "core.tracklist.add",
                               {"uri": data['uri']}))
         self.ws.send(Utils.get_message(0, "core.playback.play"))
         self.main_screen.go_to_screen('Odtwarzacz')
         Utils.speak('PLAY_URI', val=data['name'])
     else:
         Utils.speak('ENTER_DIR', val=data['name'])
    def track_playback_started(self, tl_track):
        if tl_track is not None:
            self.set_playing(True)
            # Load the data in the next screen
            self.ids.screen_manager.get_screen(self.ids.screen_manager.next()).track_playback_started(tl_track)
            self.ids.screen_manager.transition.direction = 'left'

            # Move to the next screen
            self.ids.screen_manager.current = self.ids.screen_manager.next()

            if 'length' in tl_track['track']:
                self.has_duration = True
                duration = int(tl_track['track']['length']/1000)
            else:
                self.has_duration = False
                duration = 0
            self.ids.slider.max = duration
            self.ids.slider.value = 0
            self.ids.duration.text = Utils.format_time_to_string(duration)
            if self.timer is None and self.has_duration:
                self.timer = Clock.schedule_interval(self.update, 0.1)
        else:
            self.track_playback_ended(None, 0)
示例#19
0
 def handle_event(self, message):
     if message['event'] == "handleRemoteCommand":
         self.handle_remote_command(message['cmd'])
     if message['event'] == "track_playback_started":
         Clock.schedule_once(
             partial(
                 self.listener.track_playback_started,
                 message['tl_track']), 0.2)
     elif message['event'] == "track_playback_paused":
         Clock.schedule_once(
             partial(
                 self.listener.track_playback_paused,
                 message['tl_track'],
                 message['time_position']), 0.2)
     elif message['event'] == "track_playback_resumed":
         Clock.schedule_once(
             partial(
                 self.listener.track_playback_resumed,
                 message['tl_track'],
                 message['time_position']), 0.2)
     elif message['event'] == "track_playback_ended":
         Clock.schedule_once(
             partial(
                 self.listener.track_playback_ended,
                 message['tl_track'],
                 message['time_position']), -1)
     elif message['event'] == "seeked":
         Clock.schedule_once(
             partial(self.listener.seeked, message['time_position']), -1)
     elif message['event'] == "tracklist_changed":
         self.send(
             Utils.get_message(
                 Utils.id_tracklist_loaded, 'core.tracklist.get_tl_tracks'))
     elif message['event'] == "volume_changed":
         vol = message['volume']
         self.listener.current_voulme = vol
 def track_playback_started(self, tl_track):
     self.ids.title.text = Utils.get_title_string(tl_track)
     self.ids.album.text = Utils.get_album_string(tl_track)
     self.ids.artist.text = Utils.get_artist_string(tl_track)
示例#21
0
 def on_search(self, input):
     self.ws.send(Utils.get_message(Utils.id_search_result, "core.library.search", {'any': [input.text]}))
示例#22
0
 def previous(self, event):
     if self.ids.previous_button.collide_point(*event.pos):
         self.ws.send(Utils.get_message(0, 'core.playback.previous'))
示例#23
0
    def handle_id(self, message):
        try:
            if message['id'] == Utils.id_cover_loaded:
                Clock.schedule_once(
                    partial(
                        self.listener.on_cover_loaded, message['result']), -1)
            elif message['id'] == Utils.id_tracklist_loaded:
                Clock.schedule_once(
                    partial(
                        self.listener.tracklist_changed,
                        message['result']), -1)
            elif message['id'] == Utils.id_current_track_loaded:
                self.listener.current_tl_track = message['result']
                Clock.schedule_once(
                    partial(
                        self.listener.track_playback_started,
                        message['result']), -1)
                self.send(
                    Utils.get_message(
                        Utils.id_current_time_position_loaded,
                        'core.playback.get_time_position'))
            elif message['id'] == Utils.id_current_time_position_loaded:
                Clock.schedule_once(
                    partial(self.listener.seeked, message['result']), -1)
                self.time_position = message['result']
                self.send(
                    Utils.get_message(
                        Utils.id_current_status_loaded,
                        'core.playback.get_state'))
            elif message['id'] == Utils.id_current_status_loaded:
                if message['result'] == PlaybackState.PAUSED:
                    Clock.schedule_once(
                        partial(
                            self.listener.track_playback_paused,
                            self.listener.current_tl_track,
                            self.time_position), 0.2)
                elif message['result'] == PlaybackState.STOPPED:
                    Clock.schedule_once(
                        partial(
                            self.listener.track_playback_ended,
                            self.listener.current_tl_track,
                            self.time_position), 0.2)
                else:
                    Clock.schedule_once(
                        partial(
                            self.listener.track_playback_resumed,
                            self.listener.current_tl_track,
                            self.time_position), 0.2)

            elif message['id'] == Utils.id_search_result or \
                    message['id'] == Utils.id_browse_loaded:
                Clock.schedule_once(
                    partial(
                        self.listener.result_loaded,
                        message['result'], message['id']), -1)
            elif message['id'] == Utils.id_playlists_loaded:
                Clock.schedule_once(
                    partial(
                        self.listener.playlists_loaded, message['result']), -1)
        except Exception as e:
            print(str(e))
 def update(self, dt):
     self.ids.slider.value += 0.1
     self.ids.current_pos.text = Utils.format_time_to_string(int(self.ids.slider.value))
示例#25
0
 def next(self, event):
     if self.ids.next_button.collide_point(*event.pos):
         self.ws.send(Utils.get_message(0, 'core.playback.next'))
示例#26
0
    def handle_remote_command(self, cmd):
        screen = self.listener.ids.screen_manager.get_screen(
            self.listener.ids.screen_manager.current)
        if cmd == 'fl_plus':
            Utils.backlight_up()
        if cmd == 'fl_minus':
            Utils.backlight_down()
        if cmd == 'eq':
            if Utils.lang == 'pl':
                Utils.lang = 'en'
                Utils.speak_text('English')
            else:
                Utils.lang = 'pl'
                Utils.speak_text('Polski')
        if cmd == 'ch_minus':
            screen.change_selection()
        if cmd == 'ch_plus':
            self.listener.go_to_screen('Biblioteka')
            # screen = self.listener.ids.screen_manager.get_screen(
            #     self.listener.ids.screen_manager.current)
            # screen.current_item = 0
            # screen.current_dir = [None]
            # self.send(Utils.get_message(
            #    Utils.id_browse_loaded, "core.library.browse", {'uri': None}))
            Utils.speak('CHP')
        if cmd == 'ch':
            self.listener.go_to_screen('Odtwarzacz')
            Utils.speak('CH')
        if cmd == 'vol_up':
            vol = min(int(self.listener.current_voulme) + 10, 100)
            self.send(
                Utils.get_message(
                    Utils.id_volume, 'core.mixer.set_volume', {'volume': vol}))
            # Utils.speak('VOL', val=vol)
        if cmd == 'vol_down':
            vol = max(int(self.listener.current_voulme) - 10, 0)
            self.send(Utils.get_message(
                Utils.id_volume, 'core.mixer.set_volume', {'volume': vol}))
            # Utils.speak('VOL', val=vol)
        if cmd == 'num8':
            Utils.speak('RADIO_DIR')
            self.listener.go_to_screen('Biblioteka')
            uri = url + '/Radia'
            screen = self.listener.ids.screen_manager.get_screen('Biblioteka')
            screen.current_dir = [None, url, uri]
            self.send(Utils.get_message(
                Utils.id_browse_loaded, "core.library.browse", {'uri': uri}))

        if cmd == 'num7':
            Utils.speak('AUDIOBOOKS_DIR')
            self.listener.go_to_screen('Biblioteka')
            uri = url + '/Audiobuki'
            screen = self.listener.ids.screen_manager.get_screen('Biblioteka')
            screen.current_dir = [None, url, uri]
            self.send(Utils.get_message(
                Utils.id_browse_loaded, "core.library.browse", {'uri': uri}))

        if cmd == 'num9':
            Utils.speak('MUSIC_DIR')
            self.listener.go_to_screen('Biblioteka')
            screen = self.listener.ids.screen_manager.get_screen('Biblioteka')
            uri = url + '/Muzyka'
            screen.current_dir = [None, url, uri]
            self.send(Utils.get_message(
                Utils.id_browse_loaded, "core.library.browse", {'uri': uri}))

        if cmd == 'play_pause':
            screen = self.listener.ids.screen_manager.get_screen('Odtwarzacz')
            if screen.playing:
                Utils.speak('PAUSE')
                self.send(Utils.get_message(0, 'core.playback.pause'))
            else:
                Utils.speak('PLAY')
                self.send(Utils.get_message(0, 'core.playback.play'))
        if cmd == 'next':
            screen.next_item()

        if cmd == 'prev':
            screen.prev_item()
 def previous(self, event):
     if self.ids.previous_button.collide_point(*event.pos):
         self.ws.send(Utils.get_message(0, 'core.playback.previous'))
 def seeked(self, time_position):
     self.ids.slider.value = time_position/1000
     self.ids.current_pos.text = Utils.format_time_to_string(time_position/1000)
 def track_playback_resumed(self, tl_track, time_position):
     self.set_playing(True)
     self.ids.slider.value = time_position/1000
     self.ids.current_pos.text = Utils.format_time_to_string(time_position/1000)
     if self.timer is None and self.has_duration:
         self.timer = Clock.schedule_interval(self.update, 0.1)
 def on_slider(self, event):
     if self.ids.slider.collide_point(*event.pos):
         params = {'time_position': int(self.ids.slider.value*1000)}
         self.ws.send(Utils.get_message(0, 'core.playback.seek', params))
 def next(self, event):
     if self.ids.next_button.collide_point(*event.pos):
         self.ws.send(Utils.get_message(0, 'core.playback.next'))
示例#32
0
 def args_converter(self, row_index, x):
     return {
         'text': Utils.get_title_string(x),
         'size_hint_y': None,
         'height': 45
     }
示例#33
0
 def load_cover(self, tl_track):
     if tl_track is not None:
         params = {'uris': [tl_track['track']['uri']]}
         self.ws.send(Utils.get_message(Utils.id_cover_loaded, 'core.library.get_images', params))
示例#34
0
 def start_data(self):
     self.ws.send(Utils.get_message(Utils.id_tracklist_loaded, 'core.tracklist.get_tl_tracks'))
     self.ws.send(Utils.get_message(Utils.id_current_track_loaded, 'core.playback.get_current_tl_track'))
     self.ws.send(Utils.get_message(Utils.id_playlists_loaded, 'core.playlists.as_list'))
     self.ws.send(Utils.get_message(Utils.id_browse_loaded, "core.library.browse", {'uri': None}))
示例#35
0
 def seeked(self, time_position):
     self.ids.slider.value = time_position / 1000
     self.ids.current_pos.text = Utils.format_time_to_string(time_position /
                                                             1000)
示例#36
0
 def play_pause(self, event):
     if self.ids.play_pause_button.collide_point(*event.pos):
         if self.playing:
             self.ws.send(Utils.get_message(0, 'core.playback.pause'))
         else:
             self.ws.send(Utils.get_message(0, 'core.playback.play'))
示例#37
0
 def browse(self, uri):
     self.ws.send(
         Utils.get_message(Utils.id_browse_loaded, "core.library.browse",
                           {'uri': uri}))
示例#38
0
 def on_slider(self, event):
     if self.ids.slider.collide_point(*event.pos):
         params = {'time_position': int(self.ids.slider.value * 1000)}
         self.ws.send(Utils.get_message(0, 'core.playback.seek', params))
示例#39
0
 def update(self, dt):
     self.ids.slider.value += 0.1
     self.ids.current_pos.text = Utils.format_time_to_string(
         int(self.ids.slider.value))
 def play_pause(self, event):
     if self.ids.play_pause_button.collide_point(*event.pos):
         if self.playing:
             self.ws.send(Utils.get_message(0, 'core.playback.pause'))
         else:
             self.ws.send(Utils.get_message(0, 'core.playback.play'))
 def on_selection_change(self, adapter):
     if len(self.adapter.selection) > 0:
         self.ws.send(Utils.get_message(0, "core.tracklist.clear"))
         self.ws.send(Utils.get_message(0, "core.tracklist.add", {"uri": adapter.data[adapter.selection[0].index]['uri']}))
         self.ws.send(Utils.get_message(0, "core.playback.play"))
         self.adapter.selection = []
示例#42
0
 def on_selection_change(self, adapter):
     if len(self.adapter.selection) > 0:
         self.ws.send(Utils.get_message(0, 'core.playback.play', {'tlid': self.adapter.data[self.adapter.selection[0].index]['tlid']}))
     pass