本文整理汇总了Python中mpd.MPDClient.stop方法的典型用法代码示例。如果您正苦于以下问题:Python MPDClient.stop方法的具体用法?Python MPDClient.stop怎么用?Python MPDClient.stop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mpd.MPDClient
的用法示例。
在下文中一共展示了MPDClient.stop方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import stop [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()
示例2: __init__
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import stop [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()
示例3: Jukebox
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import stop [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()
示例4: __init__
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import stop [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: __init__
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import stop [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()
示例6: stopMPD
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import stop [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
示例7: mpd
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import stop [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')
示例8: stop_radio
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import stop [as 别名]
def stop_radio():
client = MPDClient()
client.timeout = MPD_TIMEOUT
client.connect(MPD_SERVER, 6600)
client.stop()
client.close()
client.disconnect()
return ""
示例9: __init__
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import stop [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]()
示例10: main
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import stop [as 别名]
def main():
lcd = Adafruit_CharLCDPlate()
buttons = [
{
"button": lcd.SELECT,
"message": "Play",
"command": "play"
},
{
"button": lcd.LEFT,
"message": "Prev",
"command": "previous"
},
{
"button": lcd.RIGHT,
"message": "Next",
"command": "next"
}
]
client = MPDClient()
client.connect(HOST, PORT)
client.stop()
message = "VVISIGOTH\nINDUSTRIES"
lcd.begin(16,2)
lcd.clear()
lcd.backlight(lcd.BLUE)
lcd.message(message)
#mpd_message(client, "client.play()")
prev = -1
n = 0
playing = False
while True:
if n == len(buttons):
n = 0
b = buttons[n]
if lcd.buttonPressed(b['button']):
lcd.clear()
message = b['message']
# Toggle Play
if b['command'] == 'play':
print b['command']
if playing == True:
cmd = "client.stop()"
message = "Stop"
playing = False
elif playing == False:
cmd = "client.play()"
playing = True
else:
cmd = "client." + b['command'] + "()"
lcd.message(message)
mpd_message(client, cmd)
prev = b
n += 1
示例11: stop
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import stop [as 别名]
def stop():
client = MPDClient()
client.connect("localhost", 6600)
# Stop track
client.stop()
client.close()
client.disconnect()
return jsonify(ok=True)
示例12: stopMPD
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import stop [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..."
示例13: __init__
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import stop [as 别名]
class Player:
def __init__(self, host="localhost", port=6600):
self._host = host
self._port = port
self._client = MPDClient()
def _connect(self):
self._client.connect(self._host, self._port)
def _disconnect(self):
try:
self._client.disconnect()
except:
pass
def _ensure__connection(self):
try:
self._client.ping()
except (MPDError, ConnectionError, IOError):
self._disconnect()
self._connect()
def play(self, stream):
self._ensure__connection()
songId = self._client.addid(stream, 0)
self._client.playid(songId)
def stop(self):
self._ensure__connection()
self._client.stop()
def status(self):
self._ensure__connection()
return self._client.status()
def currentsong(self):
self._ensure__connection()
return self._client.currentsong()
def is_playing(self):
status = self.status()
return status['state'] == 'play'
示例14: MyMPDClient
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import stop [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'
示例15: sintetizador
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import stop [as 别名]
time.sleep(1.5)
sintetizador(consejo)
elif bool(re.search(r'radio', orden, re.IGNORECASE)):
tiempoDelUltimoMensajeEmitido = time.time()
respuesta = dialogo(entrada='radio')
print(respuesta)
sintetizador(respuesta)
radio = MPDClient()
radio.connect("localhost",6600)
radio.clear() # Limpia la playlist anterior
radio.add("http://77.92.76.134:7100") # Pone una estacion de radio en la playlist
# Busqueda de IPs de Radios en www.xatworld.com/radio-search
radio.play()
time.sleep(20) # Tiempo en el que la radio estara encendida
radio.stop()
sintetizador(respuesta[1])
orden = stt.escuchaYTranscribe()
tiempoDelUltimoMensajeEmitido = time.time()
while bool(re.search(r'si', orden, re.IGNORECASE)) or \
bool(re.search(r'continuar', orden, re.IGNORECASE)):
radio = MPDClient()
radio.connect("localhost",6600)
radio.clear() # Limpia la playlist anterior
radio.add("http://77.92.76.134:7100")
radio.play()
time.sleep(20) # Tiempo en el que la radio estara encendida
radio.stop()
sintetizador(respuesta[1])
orden = stt.escuchaYTranscribe()