def start_player(args): global help_open playlist = args[:] input_char = None while True: if not help_open: print_playlist(playlist) else: print_help() input_char = input().strip() if input_char == 'h': print_help() elif input_char == 'n': Player.instance().play_next() elif input_char == 'p': Player.instance().play() elif input_char == 'P': Player.instance().pause() elif input_char == 'r': help_open = False elif len(input_char) and input_char[0] == 'a': tracks = input_char.split(' ')[1:] for track in tracks: Player.instance().add(track) playlist.append(track) print_playlist(playlist) elif input_char == 'q': Player.instance().stop() break else: print(("Unknown command '%s'" % input_char))
def __init__(self): Gtk.VBox.__init__(self) Observer.__init__(self) Player.instance().add_observer(self) self.set_spacing(5) self.set_border_width(10) self._create_playlist() self.pack_start(self.playlist, False, False, 0) self.pack_start(self.add_track, False, False, 0) self.set_visible(False)
def update(self, event, event_type): from openmedia.player import player as event if event_type == event.PLAY_EVENT or event_type == event.NEXT_EVENT: player = Player.instance() row = self.playlist.get_row_at_index(player.curr_track_index) self.playlist.select_row(row) return False
def main(no_gui=True, args=[]): player = Player(list(set(args))) if no_gui: terminal_player.run(player, list(set(args))) else: PlayerApp() player.player_thread.keep_running = False
def __init__(self): Gtk.VBox.__init__(self, False) Observer.__init__(self) Player.instance().add_observer(self) self.button_box = Gtk.HBox() self.button_box.set_spacing(5) self._create_buttons() self.set_spacing(5) self.button_box.pack_start(self.play_button, False, False, 0) self.button_box.pack_start(self.stop_button, False, False, 0) self.button_box.pack_start(self.decrease_speed_button, False, False, 0) self.button_box.pack_start(self.play_prev_button, False, False, 0) self.button_box.pack_start(self.play_next_button, False, False, 0) self.button_box.pack_start(self.increase_speed_button, False, False, 0) self.button_box.pack_start(self.shuffle_button, False, False, 0) self.volume_box = Gtk.HBox() self.volume_box.pack_end(self.volume_button, False, True, 0) self.button_box.pack_start(self.playlist_button, False, False, 0) self.button_box.pack_end(self.volume_box, True, True, 0) self.pack_end(self.button_box, False, False, 0)
def _create_playlist(self): self.model = Gio.ListStore.new(ModelItem) self.playlist = Gtk.ListBox() self.playlist.bind_model(self.model, self._create_list_item, None) self.playlist.connect("row_activated", self._play_item) for track in Player.instance().track_list: item = ModelItem(track.name, track.duration) self.model.append(item) self.playlist.select_row(self.playlist.get_row_at_index(0)) self.add_track = Gtk.Button.new_from_icon_name(get_name("add"), Gtk.IconSize.BUTTON) self.add_track.connect("clicked", self._add_track)
def __init__(self): Gtk.Window.__init__(self, title="open-media") Observer.__init__(self) self.connect("delete-event", self.halt) Player.instance().add_observer(self) self.progress_bar = ProgressBar(Player.instance().get_song_duration()) self.control_box = ControlBox() self.playlist_box = PlaylistBox() # it contains the control buttons (play, stop etc), the playlist and # the progress bar self.upper_box = Gtk.VBox() self.album_cover = ResizableImage(Player.instance().current_track.metadata['image']) self.upper_box.pack_start(self.album_cover, False, False, 10) self.upper_box.pack_start(self.control_box, False, False, 0) self.upper_box.pack_start(self.progress_bar, False, False, 0) # contains the control box and the status widget self.control_status_box = Gtk.VBox() self.control_status_box.set_border_width(10) self.control_status_box.set_spacing(5) self._create_status_bar() self.control_status_box.pack_end(self.status_bar, False, False, 0) self.control_status_box.pack_end(Gtk.HSeparator(), False, False, 0) self.control_status_box.pack_end(self.upper_box, False, True, 0) # contains the control box, status widget and playlist box self.main_paned = Gtk.Paned.new(Gtk.Orientation.HORIZONTAL) self.main_paned.set_border_width(10) self.main_paned.set_wide_handle(True) self.main_paned.pack1(self.control_status_box, True, False) self.add(self.main_paned) self.show_all()
def _add_track(self, widget): dialog = Gtk.FileChooserDialog(Gtk.FileChooserAction.OPEN) dialog.set_transient_for(self.get_toplevel()) dialog.set_title("Add tracks to your playlist") dialog.add_button("_Open", Gtk.ResponseType.OK) dialog.add_button("_Cancel", Gtk.ResponseType.CANCEL) dialog.set_default_response(Gtk.ResponseType.OK) response = dialog.run() if response == Gtk.ResponseType.OK: player = Player.instance() if player.add(dialog.get_filename()): track_name = player.track_list[-1].name self.model.append( ModelItem(track_name, player.track_list[-1].duration)) self.show_all() dialog.destroy()
def update(self, event, event_type): from ..player import player as event player = Player.instance() if event_type == event.PLAY_EVENT or event_type == event.NEXT_EVENT: self.progress_bar.set_range(0, player.get_song_duration()) self._update_status("Playing '" + str(player.current_track.name) + "'.") self._show_image() elif event_type == event.PAUSE_EVENT or event_type == event.STOP_EVENT: if event_type == event.PAUSE_EVENT: self._update_status("Paused.") else: self._update_status("Stopped.") elif event_type == event.SLIDER_EVENT and \ not self.progress_bar.skipping: self.progress_bar.set_value(player.get_current_second()) if player.is_playing(): self._update_status("Playing '" + str(player.current_track.name) + "'.") return False
def print_playlist(args): if args: if not Player.instance().current_track: Player.instance().play() call(['clear']) print('Type "h" for help.\nYour playlist is:') for arg in args: filename = os.path.basename(arg) track_path = Player.instance().current_track.file_path if filename == os.path.basename(track_path): print(('{:<8}{:}'.format('*', filename))) else: print(('{:<8}{:}'.format('', filename))) if Player.instance().is_playing(): print('Playing') elif Player.instance().is_paused: print('Paused') else: print('Stopped') else: print_help()
def _decrease_speed(self, widget): Player.instance().decrease_playback_speed()
def _toggle_shuffle(self, widget): player = Player.instance() if player.shuffle: player.shuffle = False else: player.shuffle = True
def _volume(self, widget, value): Player.instance().set_volume(value)
def _stop(self, widget): Player.instance().stop()
def _play_previous(self, widget): Player.instance().play_previous()
def _play_next(self, widget): Player.instance().play_next()
def run(player, args=[]): Player.instance().play() runner = Thread(target=start_player, args=(args, )) runner.start() runner.join()
def _play_item(self, list_box, row): player = Player.instance() player.play(player.track_list[row.get_index()].file_path)
def _show_image(self): file_path = Player.instance().current_track.metadata['image'] self.album_cover.set_from_file(file_path) self.show_all()
def _play_pause(self, widget): player = Player.instance() if player.is_playing(): player.pause() else: player.play()
def halt(self, window, event): Player.instance().stop() Gtk.main_quit()
def _end_skip(self, widget, value): self._skipping = False Player.instance().skip(widget.get_value())