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


Python MPDClient.clear方法代码示例

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


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

示例1: main

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import clear [as 别名]
def main():
    parser = argparse.ArgumentParser(description='wake up with music')
    parser.add_argument('--playlist',
        type=str, help='foo help', default="Alarm Clock")
    parser.add_argument('--sleep',
        type=str, help='foo help', default="90 min")
    args = parser.parse_args()


    r = rxv.RXV("192.168.1.116")
    r.on = True
    time.sleep(0.5)
    r.sleep = args.sleep
    r.input = "HDMI4"
    r.volume = START_VOLUME

    cli = MPDClient()
    cli.connect("dom.wuub.net", 6600)
    cli.clear()
    cli.load(args.playlist)
    cli.play()

    for vol in range(START_VOLUME, MID_VOLUME, 1):
        r.volume = vol
        time.sleep(0.5)

    time.sleep(30)
    requests.get("http://dom.wuub.net/api/lights/small/on")

    for vol in range(MID_VOLUME, TARGET_VOLUME, 1):
        r.volume = vol
        time.sleep(2)

    time.sleep(60)
    requests.get("http://dom.wuub.net/api/lights/large/on")
开发者ID:omy09,项目名称:homeautomation,代码行数:37,代码来源:alarm_clock.py

示例2: play_playlist

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import clear [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

示例3: __init__

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import clear [as 别名]
class Player:
	def __init__(self):
	    self.client = MPDClient()
	    self.client.connect("localhost", 6600)
	    self.client.timeout = 10
	    self.client.idletimeout = None 


	def quit(self):
	    self.client.close()
	    self.client.disconnect()

	def get_playlists(self):
	    val = self.client.listplaylists()
	    return val

	def get_playing(self):
		name = "unknown"
		val = self.client.playlistinfo()
		if(len(val)>0):
			print val[0]
			name = val[0]["name"]

		return name

	def load(self,list):
		print "loading list", list
		self.client.clear()
		self.client.load(list)

	def play(self):
		self.client.play()

	def stop(self):
		self.client.stop()
开发者ID:KarlNewark,项目名称:pyPlaylist,代码行数:37,代码来源:mpc.py

示例4: Jukebox

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import clear [as 别名]
class Jukebox():
  def __init__(self):
    self.dt = DisplayThread(self)
    self.dt.start()

    ## MPD object instance
    self.client = MPDClient()
    if mpdConnect(self.client, CON_ID):
        print 'Got connected!'
    else:
        print 'fail to connect MPD server.'
        sys.exit(1)
    try:
        f = open('/media/usb/playlist.txt','r')
        playlist = f.readline().rstrip()
        print "Loading " + playlist
        self.client.clear()
        self.client.load(playlist)
    except IOError:
        print "Problem reading playlist"
    self.client.stop()
    self.client.play()

    carryOn = True
    while (carryOn):
        if (humble.switch(0)):
            time.sleep(PAUSE)
            self.toggle()
        if (humble.switch(1)):
            time.sleep(PAUSE)
            self.skip()
        if (humble.switch(2)):
            time.sleep(PAUSE)
            self.stop()
            carryOn = False
            time.sleep(PAUSE)
    # Stop the display thread
    self.dt.done()
    

  def skip(self):
      print "Skipping"
      self.client.next()

  def stop(self):
      print "Stopping"
      self.client.stop()
      humble.data.setLine(0,"")
      humble.data.setLine(1,"")
      humble.data.setLed('red', False)
      humble.data.setLed('green', False)
      time.sleep(0.5)

  def toggle(self):
      status = self.client.status()
      if status['state'] == 'pause' or status['state'] == 'stop':
          self.client.play()
      else:
          self.client.pause()
开发者ID:Cribstone,项目名称:raspberrypi,代码行数:61,代码来源:jukebox.py

示例5: __init__

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import clear [as 别名]
class Player:
	def __init__(self):
	    self.client = MPDClient()
	    self.client.connect("localhost", 6600)
	    self.client.timeout = 10
	    self.client.idletimeout = None


	def quit(self):
	    self.client.close()
	    self.client.disconnect()

	def get_playlists(self):
	    val = self.client.listplaylists()
	    return val

	def get_stats(self):
		#{'playtime': '848', 'uptime': '2565'}
		#{'songid': '33', 'playlistlength': '1', 'playlist': '86', 'repeat': '0',
		#'consume': '0', 'mixrampdb': '0.000000', 'random': '0', 'state': 'play',
		# 'elapsed': '7.476', 'volume': '-1', 'single': '0', 'time': '7:0', 'song': '0', 'audio': '44100:16:2', 'bitrate': '128'}
		all = {}
		all.update(self.client.stats())
		all.update(self.client.status())

		stats = {}
		stats["elapsed"] = all["elapsed"] if all.has_key("elapsed") else "0"
		stats["state"] = all["state"] if all.has_key("state") else "stopped"
		stats["playtime"] = all["playtime"]
		stats["uptime"] = all["uptime"]
		stats["bitrate"] = all["bitrate"] if all.has_key('bitrate') else 0
		stats["playlistlength"] = all["playlistlength"] if all.has_key("playlistlength") else 0
		stats["song"] = all["song"] if all.has_key("song") else 0
		# print stats
		return stats

	def get_playing(self):
		name = "unknown"
		val = self.client.currentsong()
		name= val["name"] if val.has_key('name') else None
		name= val["title"] if val.has_key('title') else name
		# print val
		return name

	def load(self, list):
		# print "loading list", list
		self.client.clear()
		self.client.load(list)

	def next(self):
		self.client.next()
	def prev(self):
		self.client.previous()

	def play(self):
		self.client.play()

	def stop(self):
		self.client.stop()
开发者ID:alexellis,项目名称:pyPlaylist,代码行数:61,代码来源:mpc.py

示例6: Play

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import clear [as 别名]
class Play():

    def __init__(self):
        self.client = MPDClient()               # create client object
        #client.timeout = 10                # network timeout in seconds (floats allowed), default: None
        #client.idletimeout = None          # timeout for fetching the result of the idle command is handled seperately, default: None

    def connect(self):
        try:
            self.client.connect(mpd_host, mpd_port)
            print("MPD Version: " + self.client.mpd_version)          # print the MPD version
        except OSError:
            print("Error connecting to MPD")
        except mpd.ConnectionError:
            # Already connected?
            pass

    def current_track_info(self):
        self.connect()
        try:
            return self.client.currentsong()
        except mpd.ConnectionError:
            print("[ERROR] current_track_info(): mpd.ConnectionError")
            return None
        except mpd.CommandError:
            print("[ERROR] play_album(): mpd.CommandError")
            return None

    def next_track(self):
        self.connect()
        try: 
            self.client.next()
        except mpd.ConnectionError:
            print("[ERROR] next_track(): mpd.ConnectionError")
        except mpd.CommandError:
            print("[ERROR] play_album(): mpd.CommandError")

    def pause(self):
        self.connect()
        try:
            self.client.pause()
        except mpd.ConnectionError:
            print("[ERROR] pause(): mpd.ConnectionError")
        except mpd.CommandError:
            print("[ERROR] play_album(): mpd.CommandError")

    def play_album(self, album_path):
        self.connect()
        # mpc -h 192.168.1.80 -p 6600 listall Yeah_Yeah_Yeahs/
# Maybe you need album_path[1:]?
        print("Requesting mpd play album: {}".format(album_path[1:]))
        try: 
            self.client.clear()
            self.client.add(album_path)     # [1:] to strip leading /
            self.client.play()
        except mpd.ConnectionError:
            print("[ERROR] play_album(): mpd.ConnectionError")
        except mpd.CommandError:
            print("[ERROR] play_album(): mpd.CommandError")
开发者ID:equant,项目名称:jukebox,代码行数:61,代码来源:SubiPlay.py

示例7: Radio

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import clear [as 别名]
class Radio(object):
    stations = None
    mpd = None
    position = 1
    volume = 50

    def __init__(self, stations):
        self.mpd = MPDClient()
        self.mpd.timeout = 10
        self.mpd.idletimeout = None
        self.mpd.connect("localhost", 6600)
        self.mpd.clear()
        for station in iter(stations):
            if (station != None) and (station != ""):
                self.mpd.add(station)
        self.stations = self.mpd.playlist()
        print("Successfully loaded the following playlist:")
        print(self.stations)
        print("-------")

    def increaseVolume(self):
        if self.volume < 100:
            self.volume = self.volume + 10
            self.setVolume()

    def decreaseVolume(self):
        if self.volume > 0:
            self.volume = self.volume - 10
            self.setVolume()

    def setVolume(self):
        system("amixer sset 'Master' " + str(self.volume) + "%")

    def play(self):
        system("mpc play " + str(self.position))

    def stop(self):
        system("mpc stop")

    def next(self):
        self.position = self.position + 1
        if self.position > len(self.stations):
            self.position = 1
        system("mpc play " + str(self.position))

    def prev(self):
        self.position = self.position - 1
        if self.position < 1:
            self.position = len(self.stations)
        system("mpc play " + str(self.position))

    def selectTrackUpdate(self):
        self.mpd.send_idle("currentsong")
        select([self.mpd], [], [], 10)
        self.mpd.fetch_idle()
        return self.mpd.currentsong()

    def currentStreamName(self):
        return self.streams.keys()[self.position - 1]
开发者ID:kr1schan,项目名称:tube,代码行数:61,代码来源:radio.py

示例8: stopMPD

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import clear [as 别名]
def stopMPD():
    """ Stop MPD """
    client = MPDClient()               # create client object
    client.connect("localhost", 6600)  # connect to localhost:6600
    client.clear()
    client.stop()
    client.close()
    client.disconnect()                # disconnect from the server
开发者ID:jeromefiot,项目名称:web_apiclock,代码行数:10,代码来源:functions.py

示例9: schedule_playlist

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import clear [as 别名]
def schedule_playlist(playlist_name):
    client = MPDClient()
    client.connect(settings.MPD_SERVER, settings.MPD_PORT)
    client.clear()
    client.load(playlist_name)
    client.play(1)
    client.close()
    client.disconnect()
开发者ID:Horrendus,项目名称:radiocontrol,代码行数:10,代码来源:tasks.py

示例10: __init__

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import clear [as 别名]
class mpd_client:
    def __init__(self):
        self.client = MPDClient()
        self.connect()

    def connect(self):
        self.client.timeout = None
        self.client.idletimeout = None
        self.client.connect("192.168.1.153", 6600)

    def playing(self):
        if self.client.status()["state"] == "play":
            return True
        else:
            return False

    def stop(self):
        self.client.stop()
        self.client.clear()
        self.client.random(0)

    def instant(self):
        self.client.clear()
        self.client.load("AlarmPlaylist")
        self.client.random(1)
        self.client.play()

    def mpd_command(self, command):
        client = self.client
        dict = {
            "play": client.play,
            "pause": client.pause,
            "stop": self.stop,
            "next": client.next,
            "previous": client.previous,
            "instant": self.instant,
        }
        try:
            if command not in ["vol up", "vol down"]:
                dict[command]()
            elif command == "vol up":
                vol = int(client.status()["volume"])
                if vol != -1 and vol < 99:
                    client.setvol(vol + 2)
                elif vol != -1:
                    client.setvol(100)
            elif command == "vol down":
                vol = int(client.status()["volume"])
                if vol != -1 and vol > 1:
                    client.setvol(vol - 2)
                elif vol != -1:
                    client.setvol(0)
        except "ConnectionError":
            client.connect("localhost", 6600)
            dict[command]()
开发者ID:Giannie,项目名称:Pi_Time,代码行数:57,代码来源:mpd_lib.py

示例11: jouerMPD

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import clear [as 别名]
def jouerMPD(path ='http://audio.scdn.arkena.com/11010/franceculture-midfi128.mp3'):
    """ play mpd with url playlist in arg """
    client             = MPDClient()   # create client object
    client.timeout     = 10            # network timeout in seconds (floats allowed), default: None
    client.idletimeout = None          # timeout for fetching the result of the idle command is handled seperately, default: None
    try:
        client.connect("localhost", 6600)  # connect to localhost:6600
        client.clear()
        client.add(path)
        client.play()
    except Exception :
        print "Can Connect to MPD..."
开发者ID:jeromefiot,项目名称:web_apiclock,代码行数:14,代码来源:functions.py

示例12: load_radio

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import clear [as 别名]
def load_radio():
    pls_url = get_playlist_url(RADIO_FEED_URL)

    client = MPDClient()
    client.timeout = MPD_TIMEOUT
    client.connect(MPD_SERVER, 6600)
    client.setvol(100)
    client.clear()
    client.add(pls_url)
    client.play()
    client.close()
    client.disconnect()

    return ""
开发者ID:j4y-funabashi,项目名称:orac,代码行数:16,代码来源:orac.py

示例13: stopMPD

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import clear [as 别名]
def stopMPD():
    """ Stop MPD """
    client = MPDClient()                   # create client object
    try:
        client.connect("localhost", 6600)  # connect to localhost:6600
        client.clear()
        client.stop()
        client.close()
        client.disconnect()  # disconnect from the server
        global MPDstatut     # get and modify MPD statut in navbar
        MPDstatut = client.status()['state']
        print MPDstatut
    except Exception:
        print "Can't Connect to MPD..."
开发者ID:Badaben,项目名称:APIClock,代码行数:16,代码来源:functions.py

示例14: init

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import clear [as 别名]
def init(host="localhost", port=6600, playlist="radio", columns=200):
    global mpd_client
    global mpd_host
    global mpd_port
    global diplay_columns
    mpd_host = host
    mpd_port = port
    diplay_columns = columns
    mpd_client = MPDClient()
    mpd_client.timeout = 20
    mpd_client.idletimeout = None
    mpd_client.connect(mpd_host, mpd_port)
    mpd_client.clear()
    mpd_client.load(playlist)
    mpd_client.play(0)
    mpd_client.disconnect()
开发者ID:thk4711,项目名称:raspiradio,代码行数:18,代码来源:libmpdfunctions.py

示例15: jouerMPD

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import clear [as 别名]
def jouerMPD(path ='http://audio.scdn.arkena.com/11010/franceculture-midfi128.mp3'):
    """Play mpd with url playlist in arg."""
    client = MPDClient()    # create client object
    client.timeout = 10     # network timeout in seconds
    client.idletimeout = None
    try:
        client.connect("localhost", 6600)  # connect to localhost:6600
        client.update()
        client.clear()
        client.add(path)
        client.play()
        global MPDstatut            # get and modify MPD statut in navbar
        MPDstatut = client.status()['state']
        print MPDstatut
    except Exception:
        print "Can't Connect to MPD..."
开发者ID:Badaben,项目名称:APIClock,代码行数:18,代码来源:functions.py


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