Ejemplo n.º 1
0
    def onAppStarted(self):
        """ Real initialization function, called when this module has been loaded """
        self.currTrackLength = 0
        self.sclBeingDragged = False

        # Widgets
        wTree             = prefs.getWidgetsTree()
        self.btnStop      = wTree.get_object('btn-stop')
        self.btnPlay      = wTree.get_object('btn-play')
        self.btnNext      = wTree.get_object('btn-next')
        self.btnPrev      = wTree.get_object('btn-previous')
        self.sclSeek      = wTree.get_object('scl-position')
        self.btnVolume    = wTree.get_object('btn-volume')
        self.lblElapsed   = wTree.get_object('lbl-elapsedTime')
        self.lblRemaining = wTree.get_object('lbl-remainingTime')

        # Don't show the volume button when using playbin2 and pulseaudio together (#511589)
        if not tools.isPulseAudioRunning() or prefs.getCmdLine()[0].playbin or prefs.getCmdLine()[0].volume_button:
            self.btnVolume.show()

        # Restore the volume
        volume = prefs.get(__name__, 'volume', PREFS_DEFAULT_VOLUME)
        self.btnVolume.set_value(volume)
        modules.postMsg(consts.MSG_CMD_SET_VOLUME, {'value': volume})

        # GTK handlers
        self.btnStop.connect('clicked', lambda widget: modules.postMsg(consts.MSG_CMD_STOP))
        self.btnNext.connect('clicked', lambda widget: modules.postMsg(consts.MSG_CMD_NEXT))
        self.btnPrev.connect('clicked', lambda widget: modules.postMsg(consts.MSG_CMD_PREVIOUS))
        self.btnPlay.connect('clicked', lambda widget: modules.postMsg(consts.MSG_CMD_TOGGLE_PAUSE))
        self.sclSeek.connect('change-value', self.onSeekChangingValue)
        self.sclSeek.connect('value-changed', self.onSeekValueChanged)
        self.btnVolume.connect('value-changed', self.onVolumeValueChanged)
        self.sclSeek.connect('button-press-event', self.onSeekButtonPressed)
        self.sclSeek.connect('button-release-event', self.onSeekButtonReleased)
Ejemplo n.º 2
0
    def onAppStarted(self):
        """ This is the real initialization function, called when the module has been loaded """
        wTree                  = tools.prefs.getWidgetsTree()
        self.playtime          = 0
        self.bufferedTrack     = None
        # Retrieve widgets
        self.window     = wTree.get_object('win-main')

        columns = (('',   [(gtk.CellRendererPixbuf(), gtk.gdk.Pixbuf), (gtk.CellRendererText(), TYPE_STRING)], True),
                   (None, [(None, TYPE_PYOBJECT)], False),
                  )

        self.tree = TrackTreeView(columns, use_markup=True)
        self.tree.enableDNDReordering()
        self.tree.setDNDSources([DND_INTERNAL_TARGET])

        wTree.get_object('scrolled-tracklist').add(self.tree)

        # GTK handlers
        self.tree.connect('exttreeview-button-pressed', self.onMouseButton)
        self.tree.connect('tracktreeview-dnd', self.onDND)
        self.tree.connect('key-press-event', self.onKeyboard)
        self.tree.get_model().connect('row-deleted', self.onRowDeleted)

        (options, args) = prefs.getCmdLine()

        self.savedPlaylist = os.path.join(consts.dirCfg, 'saved-playlist')
        self.paused = False


        # Populate the playlist with the saved playlist
        dump = None
        if os.path.exists(self.savedPlaylist):
            try:
                dump = pickleLoad(self.savedPlaylist)
            except:
                msg = '[%s] Unable to restore playlist from %s\n\n%s'
                log.logger.error(msg % (MOD_INFO[modules.MODINFO_NAME],
                                self.savedPlaylist, traceback.format_exc()))

        if dump:
            self.restoreTreeDump(dump)
            log.logger.info('[%s] Restored playlist' % MOD_INFO[modules.MODINFO_NAME])
            self.tree.collapse_all()
            self.select_last_played_track()
            self.onListModified()

        commands, args = tools.separate_commands_and_tracks(args)

        # Add commandline tracks to the playlist
        if args:
            log.logger.info('[%s] Filling playlist with files given on command line' % MOD_INFO[modules.MODINFO_NAME])
            tracks  = media.getTracks([os.path.abspath(arg) for arg in args])
            playNow = not 'stop' in commands and not 'pause' in commands
            modules.postMsg(consts.MSG_CMD_TRACKLIST_ADD, {'tracks': tracks, 'playNow': playNow})
        elif 'play' in commands:
            modules.postMsg(consts.MSG_CMD_TOGGLE_PAUSE)

        # Automatically save the content at regular intervals
        gobject.timeout_add_seconds(SAVE_INTERVAL, self.save_track_tree)
Ejemplo n.º 3
0
    def tryToRestore(self, tracklist):
        """ Check whether it's possible to restore playback """
        (options, args) = prefs.getCmdLine()

        # Ignore if the user provided its own tracks on the command line
        if len(args) != 0:
            return

        # Ignore if no track was being played last time
        if not self.playing or self.currTrack is None:
            return

        # Make sure the playlist is the same one
        if len(tracklist) != len(self.currTracklist):
            return

        trackIdx = -1
        for i in xrange(len(tracklist)):
            if tracklist[i] != self.currTracklist[i]:
                return

            if tracklist[i] == self.currTrack:
                trackIdx = i

        # Once here, we know playback can be resumed
        if trackIdx != -1:
            if self.paused: modules.postMsg(consts.MSG_CMD_TRACKLIST_PLAY_PAUSE, {'idx': trackIdx, 'seconds': self.currPos})
            else:           modules.postMsg(consts.MSG_CMD_TRACKLIST_PLAY,       {'idx': trackIdx, 'seconds': self.currPos})
Ejemplo n.º 4
0
 def onAppStarted(self):
     """ This is the real initialization function, called when this module has been loaded """
     self.player        = audioplayer.AudioPlayer(self.__onTrackEnded, prefs.getCmdLine()[0].playbin2)
     self.nextURI       = None
     self.queuedSeek    = None
     self.updateTimer   = None
     self.lastPlayback  = 0
     self.playbackTimer = None
Ejemplo n.º 5
0
    def updateTimerHandler(self):
        """ Regularly called during playback (can be paused) """
        if self.player.isPlaying():
            position  = self.player.getPosition()
            remaining = self.player.getDuration() - position

            modules.postMsg(consts.MSG_EVT_TRACK_POSITION, {'seconds': int(position // 1000000000)})

            if remaining < 5000000000 and self.nextURI is None and not prefs.getCmdLine()[0].playbin:
                modules.postMsg(consts.MSG_EVT_NEED_BUFFER)

        return True
Ejemplo n.º 6
0
    def onAppStarted(self):
        """ Try to fill the playlist by using the files given on the command line or by restoring the last playlist """
        (options, args)    = prefs.getCmdLine()
        self.savedPlaylist = os.path.join(consts.dirCfg, 'saved-playlist.txt')

        if len(args) != 0:
            log.logger.info('[%s] Filling playlist with files given on command line' % MOD_NAME)
            modules.postMsg(consts.MSG_CMD_TRACKLIST_SET, {'tracks': media.getTracks(args), 'playNow': True})
        else:
            try:
                tracks = [media.track.unserialize(serialTrack) for serialTrack in tools.pickleLoad(self.savedPlaylist)]
                modules.postMsg(consts.MSG_CMD_TRACKLIST_SET, {'tracks': tracks, 'playNow': False})
                log.logger.info('[%s] Restored playlist' % MOD_NAME)
            except:
                log.logger.error('[%s] Unable to restore playlist from %s\n\n%s' % (MOD_NAME, self.savedPlaylist, traceback.format_exc()))
Ejemplo n.º 7
0
    def __init__(self):
        """ Constructor """
        # The player must be created during the application startup, not when the application is ready (MSG_EVT_APP_STARTED)
        self.player = audioplayer.AudioPlayer(self.__onTrackEnded, not prefs.getCmdLine()[0].playbin)

        handlers = {
                        consts.MSG_CMD_STEP:         self.onStep,
                        consts.MSG_CMD_STOP:         self.onStop,
                        consts.MSG_CMD_PLAY:         self.onPlay,
                        consts.MSG_CMD_SEEK:         self.onSeek,
                        consts.MSG_CMD_BUFFER:       self.onBuffer,
                        consts.MSG_CMD_ENABLE_RG:    self.onEnableReplayGain,
                        consts.MSG_CMD_ENABLE_EQZ:   self.onEnableEqualizer,
                        consts.MSG_EVT_APP_STARTED:  self.onAppStarted,
                        consts.MSG_CMD_SET_CD_SPEED: self.onSetCDSpeed,
                        consts.MSG_CMD_TOGGLE_PAUSE: self.onTogglePause,
                        consts.MSG_CMD_SET_EQZ_LVLS: self.onSetEqualizerLevels,
                   }

        modules.Module.__init__(self, handlers)
Ejemplo n.º 8
0
 def bufferNextTrack(self, uri):
     """ Buffer the next track """
     if self.nextURI is None and prefs.getCmdLine()[0].playbin2:
         self.nextURI = uri
         self.player.setNextURI(uri)
Ejemplo n.º 9
0
    def onAppStarted(self):
        """ This is the real initialization function, called when the module has been loaded """
        wTree                  = tools.prefs.getWidgetsTree()
        self.playtime          = 0
        self.bufferedTrack     = None
        # Retrieve widgets
        self.window     = wTree.get_object('win-main')

        columns = (('',   [(Gtk.CellRendererPixbuf(), GdkPixbuf.Pixbuf), (Gtk.CellRendererText(), GObject.TYPE_STRING)], True),
                   (None, [(None, GObject.TYPE_PYOBJECT)], False),
                  )

        self.tree = TrackTreeView(columns, use_markup=True)

        self.tree.enableDNDReordering()
        target = Gtk.TargetEntry.new(*DND_INTERNAL_TARGET)
        targets = Gtk.TargetList.new([target])
        self.tree.setDNDSources(targets)

        wTree.get_object('scrolled-tracklist').add(self.tree)

        # GTK handlers
        self.tree.connect('exttreeview-button-pressed', self.onMouseButton)
        self.tree.connect('tracktreeview-dnd', self.onDND)
        self.tree.connect('key-press-event', self.onKeyboard)
        self.tree.get_model().connect('row-deleted', self.onRowDeleted)

        (options, args) = prefs.getCmdLine()

        self.savedPlaylist = os.path.join(consts.dirCfg, 'saved-playlist')
        self.paused = False


        # Populate the playlist with the saved playlist
        dump = None
        if os.path.exists(self.savedPlaylist):
            try:
                dump = pickleLoad(self.savedPlaylist)
            except (EOFError, IOError):
                msg = '[%s] Unable to restore playlist from %s\n\n%s'
                log.logger.error(msg % (MOD_INFO[modules.MODINFO_NAME],
                                self.savedPlaylist, traceback.format_exc()))

        if dump:
            self.restoreTreeDump(dump)
            log.logger.info('[%s] Restored playlist' % MOD_INFO[modules.MODINFO_NAME])
            self.tree.collapse_all()
            self.select_last_played_track()
            self.onListModified()

        commands, args = tools.separate_commands_and_tracks(args)

        # Add commandline tracks to the playlist
        if args:
            log.logger.info('[%s] Filling playlist with files given on command line' % MOD_INFO[modules.MODINFO_NAME])
            tracks  = media.getTracks([os.path.abspath(arg) for arg in args])
            playNow = not 'stop' in commands and not 'pause' in commands
            modules.postMsg(consts.MSG_CMD_TRACKLIST_ADD, {'tracks': tracks, 'playNow': playNow})
        elif 'play' in commands:
            modules.postMsg(consts.MSG_CMD_TOGGLE_PAUSE)

        # Automatically save the content at regular intervals
        GObject.timeout_add_seconds(SAVE_INTERVAL, self.save_track_tree)
Ejemplo n.º 10
0
 def onBuffer(self, uri):
     """ Buffer the next track """
     if not prefs.getCmdLine()[0].playbin:
         self.nextURI = uri
         self.player.setNextURI(uri)