예제 #1
0
 def __init__(self, config, bus, name='mplayer'):
     super(MPlayerService, self).__init__(config, bus)
     self.config = config
     self.bus = bus
     self.name = name
     self.index = 0
     self.normal_volume = None
     self.tracks = []
     self.mpc = MplayerCtrl()
예제 #2
0
 def __init__(self, config, bus, name='mplayer'):
     super(MPlayerService, self).__init__(config, bus)
     self.config = config
     self.bus = bus
     self.name = name
     self.index = 0
     self.normal_volume = None
     self.tracks = []
     self.mpc = MplayerCtrl()
예제 #3
0
class MPlayerService(AudioBackend):
    """
        Audio backend for mplayer.
    """
    def __init__(self, config, bus, name='mplayer'):
        super(MPlayerService, self).__init__(config, bus)
        self.config = config
        self.bus = bus
        self.name = name
        self.index = 0
        self.normal_volume = None
        self.tracks = []
        self.mpc = MplayerCtrl()

    def supported_uris(self):
        return ['file', 'http', 'https']

    def clear_list(self):
        self.tracks = []

    def add_list(self, tracks):
        self.tracks += tracks
        LOG.info("Track list is " + str(tracks))

    def play(self):
        self.stop()
        if len(self.tracks):
            # play first track
            self.mpc.loadfile(self.tracks[0])
            # add other tracks
            for track in self.tracks[1:]:
                self.mpc.loadfile(track, 1)

    def stop(self):
        self.mpc.stop()
        return True  # TODO: Return False if not playing

    def pause(self):
        if not self.mpc.paused:
            self.mpc.pause()

    def resume(self):
        if self.mpc.paused:
            self.mpc.pause()

    def next(self):
        self.index = self.index + 1
        if self.index > len(self.tracks):
            self.index = 0
            self.play()

    def previous(self):
        self.index = self.index - 1
        if self.index < 0:
            self.index = 0
            self.play()

    def lower_volume(self):
        if self.normal_volume is None:
            self.normal_volume = self.mpc.volume
            self.mpc.volume = self.mpc.volume / 3

    def restore_volume(self):
        if self.normal_volume:
            self.mpc.volume = self.normal_volume
        else:
            self.mpc.volume = 50
        self.normal_volume = None

    def track_info(self):
        """
            Fetch info about current playing track.

            Returns:
                Dict with track info.
        """
        ret = {}
        ret['title'] = self.mpc.get_meta_title()
        ret['artist'] = self.mpc.get_meta_artist()
        ret['album'] = self.mpc.get_meta_album()
        ret['genre'] = self.mpc.get_meta_genre()
        ret['year'] = self.mpc.get_meta_year()
        ret['track'] = self.mpc.get_meta_track()
        ret['comment'] = self.mpc.get_meta_comment()
        return ret

    def shutdown(self):
        """
            Shutdown mplayer

        """
        self.mpc.destroy()
예제 #4
0
class MPlayerService(AudioBackend):
    """
        Audio backend for mplayer.
    """

    def __init__(self, config, bus, name='mplayer'):
        super(MPlayerService, self).__init__(config, bus)
        self.config = config
        self.bus = bus
        self.name = name
        self.index = 0
        self.normal_volume = None
        self.tracks = []
        self.mpc = MplayerCtrl()

    def supported_uris(self):
        return ['file', 'http', 'https']

    def clear_list(self):
        self.tracks = []

    def add_list(self, tracks):
        self.tracks += tracks
        LOG.info("Track list is " + str(tracks))

    def play(self, repeat=False):
        """ Start playback of playlist.

        TODO: Add support for repeat
        """
        self.stop()
        if len(self.tracks):
            # play first track
            self.mpc.loadfile(self.tracks[0])
            # add other tracks
            for track in self.tracks[1:]:
                self.mpc.loadfile(track, 1)

    def stop(self):
        self.mpc.stop()
        return True  # TODO: Return False if not playing

    def pause(self):
        if not self.mpc.paused:
            self.mpc.pause()

    def resume(self):
        if self.mpc.paused:
            self.mpc.pause()

    def next(self):
        self.index = self.index + 1
        if self.index > len(self.tracks):
            self.index = 0
            self.play()

    def previous(self):
        self.index = self.index - 1
        if self.index < 0:
            self.index = 0
            self.play()

    def lower_volume(self):
        if self.normal_volume is None:
            self.normal_volume = self.mpc.volume
            self.mpc.volume = self.mpc.volume / 3

    def restore_volume(self):
        if self.normal_volume:
            self.mpc.volume = self.normal_volume
        else:
            self.mpc.volume = 50
        self.normal_volume = None

    def track_info(self):
        """
            Fetch info about current playing track.

            Returns:
                Dict with track info.
        """
        ret = {}
        ret['title'] = self.mpc.get_meta_title()
        ret['artist'] = self.mpc.get_meta_artist()
        ret['album'] = self.mpc.get_meta_album()
        ret['genre'] = self.mpc.get_meta_genre()
        ret['year'] = self.mpc.get_meta_year()
        ret['track'] = self.mpc.get_meta_track()
        ret['comment'] = self.mpc.get_meta_comment()
        return ret

    def shutdown(self):
        """
            Shutdown mplayer

        """
        self.mpc.destroy()