本文整理汇总了Python中mpd.MPDClient.pause方法的典型用法代码示例。如果您正苦于以下问题:Python MPDClient.pause方法的具体用法?Python MPDClient.pause怎么用?Python MPDClient.pause使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mpd.MPDClient
的用法示例。
在下文中一共展示了MPDClient.pause方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import pause [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" }'
示例2: Jukebox
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import pause [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()
示例3: Play
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import pause [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")
示例4: __init__
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import pause [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()
示例5: pause
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import pause [as 别名]
def pause():
client = MPDClient()
client.timeout = 10
client.idletimeout = None
client.connect("lounge.mpd.shack", 6600)
client.pause()
client.close()
client.disconnect()
return jsonify(status='success', action='pause')
示例6: mpd
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import pause [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')
示例7: __init__
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import pause [as 别名]
class Client:
client = None
def __init__(self):
self.client = MPDClient()
self.client.timeout = 10
self.client.idletimeout = None
self.client.connect("localhost", 6600)
def version(self):
return self.client.mpd_version
def getstatus(self):
return self.client.status()
def getcurrentsong(self):
return self.client.currentsong()
def getplaylist(self):
xs = []
for (id , file) in enumerate(self.client.playlistid()):
xs.append({'file' : file, 'id' : id})
return xs
def getplaylistsong(self,songid):
return self.client.playlistinfo()[songid]
def player(self,option):
if option == "pause":
self.client.pause(1)
else:
getattr(self.client, option)()
def playid(self,songid):
try:
self.client.playlistid(songid)
except:
return False
self.client.playid(songid)
return True
def getplayerstatus(self):
return self.client.status()["state"]
def previous(self):
self.client.previous()
return self.getcurrentsong()
def next(self):
self.client.next()
return self.getcurrentsong()
def random(self, active):
return self.client.random(active)
def repeat(self, active):
return self.client.repeat(active)
示例8: pause
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import pause [as 别名]
def pause():
client = MPDClient()
client.connect("localhost", 6600)
# Pause track
client.pause()
client.close()
client.disconnect()
return jsonify(ok=True)
示例9: main
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import pause [as 别名]
def main():
## MPD object instance
client = MPDClient()
mpdConnect(client, CON_ID)
status = client.status()
print status
timebuttonisstillpressed = 0
flashLED(0.1, 5)
updateLED(client)
while True:
try:
device = checkForUSBDevice("1GB") # 1GB is the name of my thumb drive
if device != "":
# USB thumb drive has been inserted, new music will be copied
flashLED(0.1, 5)
client.disconnect()
loadMusic(client, CON_ID, device)
mpdConnect(client, CON_ID)
print client.status()
flashLED(0.1, 5)
# wait until thumb drive is umplugged again
while checkForUSBDevice("1GB") == device:
sleep(1.0)
flashLED(0.1, 5)
if GPIO.input(BUTTON) == True:
if timebuttonisstillpressed == 0:
# button has been pressed, pause or unpause now
if client.status()["state"] == "stop":
client.play()
else:
client.pause()
updateLED(client)
elif timebuttonisstillpressed > 4:
# go back one track if button is pressed > 4 secs
client.previous()
flashLED(0.1, 5)
timebuttonisstillpressed = 0
timebuttonisstillpressed = timebuttonisstillpressed + 0.1
else:
timebuttonisstillpressed = 0
sleep(0.1)
log_message("foobar")
except Exception as e:
log_message(e.message)
示例10: MyMPDClient
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import pause [as 别名]
class MyMPDClient():
def __init__(self):
## 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)
# Auth if password is set non False
if PASSWORD:
if mpdAuth(client, PASSWORD):
print 'Pass auth!'
else:
print 'Error trying to pass auth.'
self.client.disconnect()
sys.exit(2)
def getCurrentsong(self):
return self.client.currentsong()
def pause(self):
return self.client.pause()
def previous(self):
return self.client.previous()
def _next(self):
return self.client.next()
def stop(self):
return self.client.stop()
def play(self):
return self.client.play()
def getStatus(self):
return self.client.status()
def add(self, item):
self.client.add(item)
def playlist(self):
return self.client.playlist()
def getPlaylistid(self):
return self.client.playlistid()
def playId(self,_id):
self.client.playid(_id)
def getItemIdInPLaylist(self, item):
playlist = self.getPlaylistid()
for pos in playlist:
if pos['file'] == item:
return pos['id']
return '-1'
示例11: mpd_toggle
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import pause [as 别名]
def mpd_toggle(room):
if not room in mpd_room_to_port:
return jsonify({'error': 'unkown room'})
from mpd import MPDClient
client = MPDClient()
client.connect('mpd.shack', mpd_room_to_port[room])
state = client.status()['state']
if state == 'play':
client.pause()
new_state = 'pause'
else:
client.play()
new_state = 'play'
client.close()
client.disconnect()
response = jsonify({'old_state': state,
'new_state': new_state})
return response
示例12: mpd_pause
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import pause [as 别名]
def mpd_pause():
mpd_host = settings.getSetting("mpd_host")
mpd_pass = settings.getSetting("mpd_pass")
mpd_port = int(settings.getSetting("mpd_port"))
client = MPDClient()
client.timeout = 10
client.idletimeout = None
client.connect(mpd_host, mpd_port)
if mpd_pass:
client.password(mpd_pass)
status = client.status()
if int(status.get('playlistlength', '0')) > 0:
state = status.get('state')
if state == 'play':
client.pause()
client.close()
client.disconnect()
示例13: MpdAPI
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import pause [as 别名]
#.........这里部分代码省略.........
# Make a connection to the Player
def connect(self,screenlet_settings):
pass
# The following return Strings
def get_title(self):
return self.client.currentsong().get('title')
def get_album(self):
return self.client.currentsong().get('album')
def get_artist(self):
return self.client.currentsong().get('artist')
def get_url(self):
music_dir = os.path.expanduser(self.this_mpd_music_path)
if music_dir != '':
try:
songurl = music_dir+self.client.currentsong().get('file')
return songurl
except:
return ''
else:
return ''
def get_url_dir(self):
buff = self.get_url()
for l,foo in enumerate(buff.split('/')): i=l; song=foo
return buff.replace(song, '')
def get_cover_path(self):
cover_path = ''
# Check the song folder for any PNG/JPG/JPEG image.
tmp = self.get_cover_from_path(self.get_url_dir())
if tmp: cover_path = tmp
return cover_path
# Returns Boolean
def is_playing(self):
#try:
if self.client.status().get('state') == 'play' or self.client.status().get('state') == 'pause':
return True
else:
return False
#except:
# return False
def is_paused(self):
try:
if self.client.status().get('state') == 'pause':
return True
else:
return False
except:
return False
# The following do not return any values
def play_pause(self):
if self.client.status().get('state') == 'stop':
self.client.play()
if self.client.status().get('state') == '':
self.client.play()
else:
self.client.pause()
def next(self):
self.client.next()
def previous(self):
self.client.previous()
def current_playing(self):
return self.client.status().get('songid')
def register_change_callback(self, fn):
self.callback_fn = fn
# Could not find a callback signal for Listen, so just calling after some time interval
if self.__timeout:
gobject.source_remove(self.__timeout)
self.__timeout = gobject.timeout_add(self.__interval * 1000, self.info_changed)
#self.playerAPI.connect_to_signal("playingUriChanged", self.info_changed)
def info_changed(self, signal=None):
# Only call the callback function if Data has changed
if self.__timeout:
gobject.source_remove(self.__timeout)
try:
if self.__curplaying != self.playerAPI.current_playing():
self.__curplaying = self.playerAPI.current_playing()
self.callback_fn()
if self.__nowisplaying != self.playerAPI.is_playing():
self.__nowisplaying = self.playerAPI.is_playing()
#self.redraw_background_items()
self.__timeout = gobject.timeout_add(self.__interval * 1000, self.info_changed)
except:
# The player exited ? call callback function
self.callback_fn()
self.__timeout = gobject.timeout_add(self.__interval * 1000, self.info_changed)
示例14: Mpd
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import pause [as 别名]
#.........这里部分代码省略.........
try:
self.client.disconnect()
except Exception:
self.log.exception('Error disconnecting mpd')
return False
self.connected = False
return True
def mpdAuth(self, secret):
"""
Authenticate
"""
try:
self.client.password(secret)
except CommandError:
return False
return True
def _configure(self, qtile, bar):
base._Widget._configure(self, qtile, bar)
self.layout = self.drawer.textlayout(
self.text, self.foreground, self.font, self.fontsize,
markup=True)
self.timeout_add(1, self.update)
atexit.register(self.mpdDisconnect)
def update(self):
if self.connect(True):
try:
status = self.client.status()
song = self.client.currentsong()
volume = status.get('volume', '-1')
if song:
artist = ''
title = ''
if 'artist' in song:
artist = song['artist'].decode('utf-8')
if 'title' in song:
title = song['title'].decode('utf-8')
if 'artist' not in song and 'title' not in song:
playing = song.get('file', '??')
else:
playing = u'%s − %s' % (artist, title)
if status and status.get('time', None):
elapsed, total = status['time'].split(':')
percent = float(elapsed) / float(total)
progress = int(percent * len(playing))
playing = '<span color="%s">%s</span>%s' % (
utils.hex(self.foreground_progress),
utils.escape(playing[:progress].encode('utf-8')),
utils.escape(playing[progress:].encode('utf-8')))
else:
playing = utils.escape(playing)
else:
playing = 'Stopped'
playing = '%s [%s%%]' % (playing,
volume if volume != '-1' else '?')
except Exception:
self.log.exception('Mpd error on update')
playing = self.msg_nc
self.mpdDisconnect()
else:
if self.reconnect:
playing = self.msg_nc
else:
return False
if self.text != playing:
self.text = playing
self.bar.draw()
return True
def click(self, x, y, button):
if not self.connect(True):
return False
try:
status = self.client.status()
if button == 3:
if not status:
self.client.play()
else:
self.client.pause()
elif button == 4:
self.client.previous()
elif button == 5:
self.client.next()
elif button == 8:
if status:
self.client.setvol(
max(int(status['volume']) - self.inc, 0))
elif button == 9:
if status:
self.client.setvol(
min(int(status['volume']) + self.inc, 100))
except Exception:
self.log.exception('Mpd error on click')
示例15: add_weather_tracks
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import pause [as 别名]
return [status['song'],status['playlistlength']]
def add_weather_tracks(client):
client.add('tts.mp3')
# client.add('tts.mp3')
def move_weather_tracks(client):
current = current_track(client)
client.move(int(current[1])-1,current[0])
# client.move(int(current[1])-1,current[0])
add_weather_tracks(client)
move_weather_tracks(client)
client.setvol(90)
client.random(0)
current = current_track(client)
texttospeech.speakSpeechFromText(forecast.full_report1)
client.play(int(current[0])-1)
client.idle()
client.idle()
client.pause()
texttospeech.speakSpeechFromText(forecast.full_report2)
client.previous()
client.idle()
client.idle()
client.setvol(85)
client.random(1)
client.close()
client.disconnect()