当前位置: 首页>>代码示例>>Python>>正文


Python MPDClient.shuffle方法代码示例

本文整理汇总了Python中mpd.MPDClient.shuffle方法的典型用法代码示例。如果您正苦于以下问题:Python MPDClient.shuffle方法的具体用法?Python MPDClient.shuffle怎么用?Python MPDClient.shuffle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mpd.MPDClient的用法示例。


在下文中一共展示了MPDClient.shuffle方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: play_playlist

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import shuffle [as 别名]
def play_playlist(name):
    client=MPDClient()
    mopidyAddress = 'localhost'
    mopidyPort = 6600

    client.timeout = 10
    client.idletimeout = None
    client.connect(mopidyAddress,mopidyPort)
    #client.password('IlPits2013')
    client.clear()
    if playlist_exists(name):
        client.load(name)
    spotify_lists = get_spotify_playlists()
    name = name.encode('utf-8')
    print name
    #print spotify_lists
    if name in spotify_lists:
        add_spotify_directory(name)
    #time.sleep(1)
    if name == 'Pierre':
        client.shuffle()

    #client.setvol(50)
    #client.play()
    client.disconnect()
    return
开发者ID:NilsNoreyson,项目名称:phoneBookServer,代码行数:28,代码来源:get_phonebook_files.py

示例2: MusicPlayer

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import shuffle [as 别名]
class MusicPlayer(Action):
    """MusicPlayer for Alfred"""
    def __init__(self, cfg):
        super(MusicPlayer, self).__init__(cfg)
        self.triggers = ["music","audio"]
        self.mpd = MPDClient()
        self.mpd.connect("localhost", "6600")
        self.mpd.consume(0)

    def _do_update(self, command):
        self.mpd.update()

    def _do_list(self, command):
        llista = self.mpd.list('file')
        print llista
        if len(llista) > 0:
            return "\n".join(llista)
        else:
            return "Empty List SIR"

    def _do_add(self, command):
        song = " ".join(command[1:])
        self.mpd.add(song)
        return "Song %s Added SIR" % (song)

    def _do_queue(self,command):
        return "list: %s" % (self.mpd.playlist())

    def _do_clear(self, command):
        self.mpd.clear()
        return "Clear Done SIR"

    def _do_next(self, command):
        self.mpd.next()
        return "Next Song Done SIR"

    def _do_previous(self, command):
        self.mpd.previous()
        return "Previous Song Done SIR"

    def _do_pause(self, command):
        self.mpd.pause()
        return "Music Paused SIR"

    def _do_shuffle(self, command):
        self.mpd.shuffle()
        return "Music shuffled SIR"

    def _do_repeat(self, command):
        try:
            if command[1] == "on":
                self.mpd.repeat(1)
                return "Repeat Set On SIR"
            elif command[1] == "off":
                self.mpd.repeat(0)
                return "Repeat Set Off SIR"
            else:
                return "Error SIR"
        except:
            return "Error SIR"

    def _do_play(self, command):
        try:
            songpos = command[1]
            self.mpd.play(int(songpos))
            return "Playing %s Song Done SIR" % (songpos)
        except:
            self.mpd.play()
            return "Music Playing SIR"

    def _do_stop(self, command):
        self.mpd.stop()
        return "Music Stoped SIR"

    def do(self, command):
        print "Will", " ".join(command), "music"
        print command
        if command[0] == "update":
            self._do_update(command)
        elif command[0] == "list":
            return self._do_list(command)
        elif command[0] == "add":
            return self._do_add(command)
        elif command[0] == "queue":
            return self._do_queue(command)
        elif command[0] == "play":
            return self._do_play(command)
        elif command[0] == "stop":
            return self._do_stop(command)
        elif command[0] == "clear":
            return self._do_clear(command)
        elif command[0] == "next":
            return self._do_next(command)
        elif command[0] == "previous":
            return self._do_previous(command)
        elif command[0] == "pause":
            return self._do_pause(command)
        elif command[0] == "repeat":
            return self._do_repeat(command)
        elif command[0] == "shuffle":
#.........这里部分代码省略.........
开发者ID:Costar93,项目名称:Alfred,代码行数:103,代码来源:MusicPlayer.py

示例3: raspberry_explorer_board

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import shuffle [as 别名]
def raspberry_explorer_board():

    logger = Logger().getLogger()
    config = Configuration()
    # Connect to MPD
    client = MPDClient() 
    client.connect("localhost", int(config.iniFile.get('mpd','port')))

    # Connect to NFC Explorer board
    logger.info('Connect to nxppy Mifare')
    mifare = nxppy.Mifare()

    # Initialize storage
    logger.info('Connect to Redis')
    storage = redis.StrictRedis(host='localhost', port=int(config.iniFile.get('redis','port')), db=0)

    # Count pauses to make sure it is not a error reading
    nbPause = 0
    # Keep previous uid to compare with current one
    previous_uid = None
    # Data from taf
    data = None

    if mifare is None:
        logger.info("Error while loading NFC Explorer Board")
    else:
        logger.info("Reader NFC Raspberry is now running")

        while True:
            try:
                uid = mifare.select()
                if uid is not None:
                    if uid == previous_uid:
                        nbPause = 0
                        if data:
                            status = client.status()
                            if status['state'] == 'stop':
                                logger.info("Play")
                                storage.set('current-tag-id', uid)
                                client.play(0)
                            if status['state'] == 'pause':
                                logger.info("Continue")
                                storage.set('current-tag-id', uid)
                                client.pause(0)
                        else:
                            pass
                    else:
                        previous_uid = uid

                        logger.info("New chip detected : %s" % uid)
                        # Save current-tag-id in memory to be used by services
                        storage.set('current-tag-id', uid)

                        # Stop mpd and 
                        client.stop()   
                        client.clear()

                        # Get from storage list of songs to play
                        tag = storage.get("tags:" + uid)

                        if tag is None:
                            logger.info("Unknown chip %s" % uid)
                            data = None
                        else:
                            # Load data
                            data = json.loads(tag)

                            logger.info(data)

                            # Configure MPD server
                            client.random(1 if data['random'] else 0)
                            client.repeat(1 if data['repeat'] else 0)

                            # Add songs
                            for song in data['songs']:
                                client.add(song)

                            if data['random']:
                                client.shuffle()

                            client.play(0)
                    
            except nxppy.SelectError:

                # Random error reading. Avoi
                if nbPause == 2:
                    nbPause = 0
                    # If play then 
                    if client.status()['state'] == 'play':
                        logger.info("Detect missing chip")
                        logger.info("Pause")
                        storage.delete('current-tag-id')
                        client.pause(1)
                    # If us
                    elif previous_uid and not data:
                        previous_uid = None
                        storage.delete('current-tag-id')
                else:
                    nbPause = nbPause + 1
            except Exception as e:
#.........这里部分代码省略.........
开发者ID:mpd-box,项目名称:mpd-box,代码行数:103,代码来源:raspberry_explorer_board.py

示例4: __init__

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import shuffle [as 别名]

#.........这里部分代码省略.........
        """
        Toggles between paused and playing
        Scenarios of current song
        Not Playing: Plays the song
        Paused: Resumes playback
        Playing: Pauses song
        If no songs are in the queue, it does nothing
        """
        if self.__state() == 'play':
            self.api_pause()
        elif self.__state() == 'pause' or not len(self.queue) == 0:
            self.api_play()

    def api_next(self):
        """
        Plays the next song in the queue
        If no songs are left it does nothing
        """
        self.__api.next()

    def api_stop(self):
        """
        Stops playback
        If no songs are in the queue, it does nothing
        """
        self.__api.stop()

    def api_previous(self):
        """
        Plays the previous song in the queue.
        """
        self.__api.previous()

    def api_shuffle(self):
        """
        Shuffles entire playlist.  Probably should not be used.
        """
        self.__api.shuffle()

    def api_clear_queue(self):
        """
        Clears the queue of all the songs.
        If the queue is already cleared, this will do nothing.
        """
        self.__api.clear()

    def api_add_favorite(self):
        """
        Favorites the current song
        This will add it to your library as well
        If the song is already favorited, this will do nothing
        If no song is playing or selected in the queue, nothing
        will happen
        """
        raise NotImplementedError

    def api_remove_favorite(self):
        """
        If the current song is favorited, it will unfavorite it
        If the song is not favorited, this will do nothing
        """
        raise NotImplementedError

    def api_toggle_favorite(self):
        """
        Toggles the favorite status of the current song
开发者ID:Qalthos,项目名称:groovebot,代码行数:70,代码来源:MPDApi.py


注:本文中的mpd.MPDClient.shuffle方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。