本文整理汇总了Python中mpd.MPDClient.single方法的典型用法代码示例。如果您正苦于以下问题:Python MPDClient.single方法的具体用法?Python MPDClient.single怎么用?Python MPDClient.single使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mpd.MPDClient
的用法示例。
在下文中一共展示了MPDClient.single方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _add_to_mopidy
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import single [as 别名]
def _add_to_mopidy(self, track_id):
""" Play a mopidy compatible track """
client = MPDClient()
client.connect(MOPIDY_HOST, MOPIDY_PORT)
client.single(1)
client.clear()
try:
client.add(track_id)
client.play(0)
except CommandError as e:
self.print_queue.put("Failed to add song to Mopidy: " + str(e))
client.close()
client.disconnect()
def quit():
mpd_exec("stop")
interrupt_main()
def status():
song = mpd_exec("currentsong")
status = mpd_exec("status")
# TODO: make prettier...
status_line = song['artist'] + ' - ' + song['title'] + '\n' + \
'[' + status['state'] + '] ' + status['elapsed']
self.print_queue.put(status_line)
def toggle():
mpd_exec("pause")
status()
def play():
mpd_exec("play")
def stop():
mpd_exec("stop")
self.set_cmd_map({"pause": toggle,
"play": play,
"stop": stop,
"toggle": toggle,
"quit": quit,
"status": status})
self._mopidy_idle()
示例2: myMPD
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import single [as 别名]
#.........这里部分代码省略.........
# "password commmand failed: %s" %
# (self._host, e))
#db.write_log_to_db_a(ac, "MPD-PW-Error: %s" % str(e), "x",
# "write_also_to_console")
return None
# Catch all other possible errors
except (MPDError, IOError) as e:
#raise RunError("Could not connect to '%s': "
# "error with password command: %s" %
# (self._host, e))
db.write_log_to_db_a(ac, "MPD-Error-2: %s" % str(e), "x",
"write_also_to_console")
return None
def disconnect(self):
# Try to tell MPD we're closing the connection first
try:
self._client.close()
# If that fails, don't worry, just ignore it and disconnect
except (MPDError, IOError):
pass
try:
self._client.disconnect()
# Disconnecting failed, so use a new client object instead
# This should never happen. If it does, something is seriously broken,
# and the client object shouldn't be trusted to be re-used.
except (MPDError, IOError):
self._client = MPDClient()
def exec_command(self, db, ac, command, value):
"""spread out exec commands"""
result = None
try:
if command == "access":
result = self.mpd_access(db, ac)
if command == "play":
result = self._client.play()
if command == "update":
result = self._client.update()
if command == "song":
result = self._client.currentsong()
if command == "status":
result = self._client.status()
if command == "add":
result = self._client.add(value)
if command == "consume":
result = self._client.consume(value)
if command == "crossfade":
result = self._client.crossfade(value)
if command == "seek":
result = self._client.seek(value)
if command == "repeat":
result = self._client.repeat(value)
if command == "random":
result = self._client.random(value)
if command == "single":
result = self._client.single(value)
if command == "replay_gain_mode":
result = self._client.replay_gain_mode(value)
if command == "next":
result = self._client.next()
if command == "setvol":
result = self._client.setvol(value)
# via mpc-client
if command == "crop":
result = mpc_client(db, ac, "crop", value)
if command == "vol":
result = mpc_client(db, ac, "volume", value)
# via os
if command == "reload-1":
result = run_cmd(db, ac, "killall", value)
if command == "reload-2":
result = run_cmd(db, ac, "mpd", value)
return result
# Couldn't get the current cmd, so try reconnecting and retrying
except (MPDError, IOError) as e:
# No error handling required here
# Our disconnect function catches all exceptions, and therefore
# should never raise any.
error_msg = "MPD-Error-3: %s" % str(e)
if value is not None:
error_msg = error_msg + ", cmd: " + value
#db.write_log_to_db_a(ac, "MPD-E-3 cmd-value: " + value, "x",
# "write_also_to_console")
if str(e) == "Not connected":
error_msg = error_msg + ", try recon.:"
db.write_log_to_db_a(ac, error_msg, "x",
"write_also_to_console")
self.connect(db, ac)
self.exec_command(db, ac, command, value)
else:
db.write_log_to_db_a(ac, error_msg, "x",
"write_also_to_console")
return None
示例3: declarative_base
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import single [as 别名]
from sqlalchemy import create_engine, Column, Integer, String
import soundcloud
from mpd import MPDClient
Base = declarative_base()
yt = YouTube()
engine = create_engine('sqlite:///sj.db', echo=True)
Session = sessionmaker(bind=engine)
started = False
app = Flask(__name__)
media_player = MPDClient()
media_player.connect('localhost', 6600)
media_player.consume(1)
media_player.single(1)
class SongPlayer():
def __init__(self, session, media_player, event):
self.Session = session
self.media_player = media_player
self.playing = False
self.current_url = None
self.current_title = None
self.current_ourl = None
self.event = event
def run(self):
self.next_song()
示例4: MPDClientDriver
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import single [as 别名]
#.........这里部分代码省略.........
return False
else:
return True
@connect_mpd
def _set_random(self, state):
"""Set random state
"""
if state:
self.cli.random(1)
else:
self.cli.random(0)
@catchsocketerror
def _get_repeat(self):
"""Returns repeat state
"""
if self._read_status_key('repeat') == '0':
return False
else:
return True
@connect_mpd
def _set_repeat(self, state):
"""Set repeat state
"""
if state:
self.cli.repeat(1)
else:
self.cli.repeat(0)
@catchsocketerror
def _get_single(self):
"""Returns single state
"""
if self._read_status_key('single') == '0':
return False
else:
return True
@connect_mpd
def _set_single(self, state):
"""Set single state
"""
if state:
self.cli.single(1)
else:
self.cli.single(0)
@catchsocketerror
def _get_volume(self):
"""Returns volume
"""
return self._read_status_key('volume')
@connect_mpd
def _set_volume(self, value):
"""Set volume
"""
self.cli.volume(value)
@catchsocketerror
def _get_state(self):
"""Get current state
"""
示例5: delete_event
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import single [as 别名]
#.........这里部分代码省略.........
if self.nItr != None:
#self.curartist = self.tree.get_value(self.nItr, 0)
self.curartist = self.tree.get_value(self.tree.get_iter_from_string(str(self.rbox.get_cursor()[0][0])), 0)
albums = self.mclient.list("album", self.curartist)
self.tree.clear()
for al in albums:
if al != "":
self.tree.append([al])
self.rbox.scroll_to_cell('0', column=None)
elif self.tracks == True:
if self.nItr != None:
#self.curalbum = self.tree.get_value(self.nItr, 0)
self.curalbum = self.tree.get_value(self.tree.get_iter_from_string(str(self.rbox.get_cursor()[0][0])), 0)
tracks = self.mclient.find("album", self.curalbum)
self.tree.clear()
for t in tracks:
self.tree.append([t['title']])
self.rbox.scroll_to_cell('0', column=None)
elif self.options == True:
self.tree.clear()
options = self.mclient.status()
if options['consume'] == '0':
self.tree.append(["Toggle consume [off]"])
else:
self.tree.append(["Toggle consume [on]"])
if options['repeat'] == '0':
self.tree.append(["Toggle repeat [off]"])
else:
self.tree.append(["Toggle repeat [on]"])
if options['random'] == '0':
self.tree.append(["Toggle random [off]"])
else:
self.tree.append(["Toggle random [on]"])
if options['single'] == '0':
self.tree.append(["Toggle single [off]"])
else:
self.tree.append(["Toggle single [on]"])
self.rbox.scroll_to_cell('0', column=None)
size = self.window.get_default_size()
self.window.resize(size[0], size[1]+50)
self.lbox.hide()
self.scrollbox.show()
self.window.set_focus(self.rbox)
self.nItr = self.tree.get_iter_root()
def mpdCmd(self):
if self.current == True:
songTitle = self.tree.get_value(self.tree.get_iter_from_string(str(self.rbox.get_cursor()[0][0])), 0)
songTitle = songTitle.split("\t")[0]
songid = self.list[songTitle]
self.mclient.playid(songid)
self.music = False
#self.mclient.disconnect()
self.destroy(self, data=None)
elif self.artist == True:
#artist = self.tree.get_value(self.nItr, 0)
artist = self.tree.get_value(self.tree.get_iter_from_string(str(self.rbox.get_cursor()[0][0])), 0)
self.mclient.add(artist)
self.mclient.play()
elif self.album == True:
#album = self.tree.get_value(self.nItr, 0)
album = self.tree.get_value(self.tree.get_iter_from_string(str(self.rbox.get_cursor()[0][0])), 0)
self.mclient.findadd("album", album)
示例6: __init__
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import single [as 别名]
class player:
def __init__(self, channelList):
print ("Taste drücken, um Song abzuspielen, CTRL+C beendet das Programm.")
self.client = MPDClient()
# Configure MPD connection settings
self.host = 'localhost'
self.port = '6600'
self.initGPIO(channelList)
self.updateAndLoadLatestsPlaylist()
self.stopPlaybackAfterCurrentSong()
self.andNowWaitForButtonClicksAndHandleThem()
def initGPIO(channelList):
print("Initializing GPIO pins ...")
GPIO.setmode(GPIO.BCM)
GPIO.setup(channelList, GPIO.IN)
@contextmanager
def connectionToMpdServer(self):
try:
self.client.connect(self.host, self.port)
yield
finally:
self.client.close()
self.client.disconnect()
def updateAndLoadLatestsPlaylist(self):
with self.connectionToMpdServer():
print('Loading playlist ...')
self.client.update()
self.client.clear()
os.system("mpc ls | mpc add")
print self.client.playlist()
print('--------------------')
def stopPlaybackAfterCurrentSong(self):
with self.connectionToMpdServer():
self.client.single(1)
def andNowWaitForButtonClicksAndHandleThem(self):
while True:
if GPIO.input(PLAY01) == True:
self.handleButtonClick(self.client, '0')
if GPIO.input(PLAY02) == True:
self.handleButtonClick(self.client, '1')
if GPIO.input(PLAY03) == True:
self.handleButtonClick(self.client, '2')
sleep(0.1);
def handleButtonClick(self, client, song):
with self.connectionToMpdServer():
status = self.client.status()["state"]
if (status == "play" or status == "pause"):
if self.client.currentsong()["pos"] == song:
self.client.pause()
elif self.client.currentsong()["pos"] != song:
self.client.stop()
self.client.play(song)
elif status == "stop":
self.client.play(song)
else:
print("Error")
示例7: Controller
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import single [as 别名]
class Controller(object):
class Mode:
NONE = 0
QUEUE = 1
RANDOM = 2
def __init__(self, host="/run/mpd/socket"):
self.cli = MPDClient()
self.cli.timeout = 10
self.cli.idletimeout = None
self.cli.connect(host, 0)
log.info("Controller connected to MPD server version %s" % self.cli.mpd_version)
self.mode = Controller.Mode.NONE
self.switch_mode(Controller.Mode.RANDOM)
def add_song(self, song):
self.cli.add(song.as_mpd())
def add_playlist(self, playlist):
map(self.cli.add, playlist.as_mpd())
def switch_mode(self, mode):
self.mode = Controller.Mode.RANDOM
if mode == Controller.Mode.RANDOM:
self.cli.consume(0)
self.cli.random(1)
self.cli.repeat(1)
self.cli.single(0)
self.cli.clear()
# Load up a ton of random songs
playlist = Song.as_mpd_playlist(Song.select())
map(self.cli.add, playlist)
if mode == Controller.Mode.QUEUE:
self.cli.consume(1)
self.cli.random(0)
self.cli.repeat(0)
self.cli.single(0)
self.cli.clear()
def status(self):
current_song = self.cli.currentsong()
status = self.cli.status().items() + current_song.items()
if 'title' in current_song:
try:
s = Song.get(Song.title == current_song['title'])
status += s.to_dict().items()
except Song.DoesNotExist: pass
status = dict(status)
status['playlist'] = self.cli.playlistinfo()
return status
def play(self):
self.cli.play()
def pause(self):
self.cli.pause()
def stop(self):
self.cli.stop()
def previous(self):
self.cli.previous()
def next(self):
self.cli.next()
def seek(self, ts):
self.cli.seekcur(ts);