本文整理汇总了Python中mpd.MPDClient.play方法的典型用法代码示例。如果您正苦于以下问题:Python MPDClient.play方法的具体用法?Python MPDClient.play怎么用?Python MPDClient.play使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mpd.MPDClient
的用法示例。
在下文中一共展示了MPDClient.play方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import play [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()
示例2: main
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import play [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")
示例3: main
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import play [as 别名]
def main():
## MPD object instance
client = MPDClient()
mpdConnect(client, CON_ID)
print client.status()
timeButtonIsPressed = 0
playCounter = 0
while True:
print client.status()
## respond to the button press
if GPIO.input(BUTTON) == True:
if timeButtonIsPressed == 1:
# button has been pressed 1 sec, stop or play now
if client.status()["state"] == "stop":
loadMusic()
client.play()
else:
client.stop()
timeButtonIsPressed = timeButtonIsPressed + 0.1
else:
timeButtonIsPressed = 0
if client.status()["state"] == "play":
playCounter += 0.1
sleep(0.1)
if playCounter > 1800
fadeOut()
示例4: onevent
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import play [as 别名]
def onevent(msg):
# add song if needed
client = MPDClient()
client.connect("localhost", 6600)
client.use_unicode = True
if client.status()["playlistlength"] == '0' and autoaddstate == 1:
song = choose_from_list(current_list)
client.add(song)
# while client.status()['state']=='stop':
client.play()
# currentsong info
if 'player' in msg or 'playlist' in msg:
print("publish currentsong")
currentsong = client.currentsong()
print(currentsong)
# pre-treat the data if artist/title not present:
if 'title' not in currentsong.keys():
currentsong['artist'] = "?"
if 'file' in currentsong.keys():
currentsong['title'] = currentsong['file'].split('/')[-1]
yield app.session.publish('radio.updatesong', currentsong)
# player status info
if ('player' in msg or
'mixer' in msg or
'options' in msg or
'playlist' in msg):
print("publish player status")
status = client.status()
status[u'autoadd'] = autoaddstate
yield app.session.publish('radio.updatestatus', status)
# playlist info
if 'playlist' in msg:
print("publish playlist")
playlist = client.playlistinfo()
print(playlist)
playlist_trim = []
for song in playlist:
song_trim = {}
if 'http' in song['file']:
song_trim['artist'] = song['file']
song_trim['title'] = ''
song_trim['time'] = 9999
song_trim['id'] = song['id']
else:
if 'title' not in song.keys() or 'artist' not in song.keys():
song_trim['artist'] = "?"
if 'file' in song.keys():
song_trim['title'] = song['file'].split('/')[-1]
else:
song_trim['artist'] = song['artist']
song_trim['title'] = song['title']
song_trim['id'] = song['id']
song_trim['time'] = song['time']
playlist_trim.append(song_trim)
yield app.session.publish('radio.updateplaylist', playlist_trim)
client.close()
示例5: main
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import play [as 别名]
def main():
print "Content-Type: application/json\n"
client = MPDClient()
if not mpdConnect(client, CON_ID):
print '{ "status": "failure", "message": "failed to connect to MPD server. '+HOST+':'+PORT+'"}'
sys.exit(-1)
if PASSWORD != '':
if not mpdAuth(client, PASSWORD):
print '{ "status": "failure", "message": "failed to auth against MPD server."}'
sys.exit(-1)
command = os.environ['SCRIPT_NAME'].replace('/mpd/control/', '')
try:
if command == 'pause/':
client.pause()
print '{ "status": "success" }'
elif command == 'play/':
client.play()
print '{ "status": "success" }'
elif command == 'next/':
client.next()
print '{ "status": "success" }'
elif command == 'previous/':
client.previous()
print '{ "status": "success" }'
except CommandError:
print '{ "status": "failure", "message": "unknown command" }'
示例6: Play
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import play [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")
示例7: __init__
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import play [as 别名]
class MPDCli:
def __init__(self, ipaddress):
self.client = MPDClient()
self.client.timeout = 10
self.client.idletimeout = None
self.client.connect(ipaddress, 6600)
self.client.consume(0)
self.ip = ipaddress
def close(self):
self.client.close()
self.client.disconnect()
def __tryConnect(self):
try:
self.client.update()
except ConnectionError:
self.client.connect(self.ip, 6600)
self.client.update()
def getNowPlaying(self):
self.__tryConnect()
return self.client.currentsong()
def getCurrentStatus(self):
self.__tryConnect()
return self.client.status()
def play(self):
self.__tryConnect()
currentState = self.client.status()['state']
if currentState == 'stop':
self.client.play(int(self.client.status()['song']))
else:
self.client.pause()
return self.client.status()
def stop(self):
self.__tryConnect()
self.client.stop()
return self.client.status()
def prev(self):
self.__tryConnect()
self.client.previous()
return self.client.status()
def next(self):
self.__tryConnect()
self.client.next()
return self.client.status()
def idle(self):
self.__tryConnect()
self.client.idle()
示例8: __init__
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import play [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()
示例9: Jukebox
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import play [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()
示例10: schedule_playlist
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import play [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()
示例11: play
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import play [as 别名]
def play():
client = MPDClient()
client.timeout = 10
client.idletimeout = None
client.connect("lounge.mpd.shack", 6600)
client.play()
client.close()
client.disconnect()
return jsonify(status='success', action='play')
示例12: mpd
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import play [as 别名]
def mpd(bot, trigger):
"""Used to control the mpd music player at the space"""
rulenum = trigger.group(2)
## MPD object instance
client = MPDClient()
try:
client.connect(host=HOST, port=PORT)
except SocketError:
bot.say('socketerror')
exit(1)
# Auth if password is set non False
if PASSWORD:
try:
client.password(PASSWORD)
except CommandError:
client.disconnect()
sys.exit(2)
mpdcommand = str(rulenum)
if ((mpdcommand == 'playing') or (mpdcommand == 'state')) :
currentsong = client.currentsong()
currentstatus = client.status()
if currentstatus['state'] == 'play':
saySong(bot,currentsong)
elif currentstatus['state'] == 'pause':
bot.say('Music is currently paused (' + songNow(currentsong) + ')')
elif currentstatus['state'] == 'stop':
bot.say('No music is playing')
elif mpdcommand == 'play':
bot.say('Pressing play on mpd...')
client.play()
currentsong = client.currentsong()
saySong(bot,currentsong)
elif mpdcommand == 'pause':
bot.say('Pausing mpd...')
client.pause()
elif mpdcommand == 'stop':
bot.say('Stopping mpd...')
client.stop()
elif mpdcommand == 'next':
bot.say('Moving to next song on mpd...')
client.next()
currentsong = client.currentsong()
saySong(bot,currentsong)
else:
bot.say('invalid mpd command')
示例13: play_MPD
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import play [as 别名]
def play_MPD(path):
""" Joue MPD avec comme argument le chemin du fichier à jouer """
client = MPDClient() # create client object
client.timeout = 10 # network timeout in seconds (floats allowed), default: None
client.idletimeout = None
client.connect("localhost", 6600) # connect to localhost:6600
MPDClient.add(path)
client.play(0)
print MPDClient.playlistinfo()
示例14: __init__
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import play [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]()
示例15: play
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import play [as 别名]
def play():
client = MPDClient()
client.connect("localhost", 6600)
# Play track
client.play()
client.close()
client.disconnect()
return jsonify(ok=True)