本文整理汇总了Python中mpd.MPDClient.setvol方法的典型用法代码示例。如果您正苦于以下问题:Python MPDClient.setvol方法的具体用法?Python MPDClient.setvol怎么用?Python MPDClient.setvol使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mpd.MPDClient
的用法示例。
在下文中一共展示了MPDClient.setvol方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mpdInit
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import setvol [as 别名]
def mpdInit():
global client
client = MPDClient()
client.timeout = 10
client.idletimeout = None
client.connect("localhost", 6600)
client.password("1234")
client.setvol(20)
return client
示例2: volume
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import setvol [as 别名]
def volume(value):
client = MPDClient()
client.connect("localhost", 6600)
client.setvol(value)
client.close()
client.disconnect()
return jsonify(ok=True, value=value)
示例3: load_radio
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import setvol [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 ""
示例4: init
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import setvol [as 别名]
def init():
global CLIENT, PLAYLIST, LIBRARY
## MPD object instance
CLIENT = MPDClient()
if mpdConnect(CLIENT, CON_ID):
logging.info('Connected to MPD server')
CLIENT.setvol(95)
PLAYLIST = CLIENT.playlistinfo()
LIBRARY = CLIENT.listallinfo()
repeat(True) # Repeat all tracks
else:
logging.critical('Failed to connect to MPD server')
logging.critical("Sleeping 1 second and retrying")
time.sleep(1)
init()
示例5: Communicator
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import setvol [as 别名]
#.........这里部分代码省略.........
"""
try:
self.__disconnect()
except ConnectionError:
pass
def __connect(self, hostname,port):
"""
Connect to MPD-server.
Args:
hostname: Hostname of MPD-server.
port: Port of MPD-Server
"""
self.__client.connect(hostname,port)
@remoteAccess
def __disconnect(self):
"""
Disconnect from server.
"""
self.__client.disconnect()
@remoteAccess('Getting status not possible')
def get_status(self):
"""
Returns status of MPD-daemon.
"""
return self.__client.status()
@remoteAccess('Error updating playlist')
def get_playlist(self):
"""
Returns the playlist from server.
"""
return self.__client.playlistinfo()
###MPD CONTROL###
@remoteAccess('Error during control access.')
def play(self, songid):
"""
Start playing the song with songid.
Args:
songid: Song ID in the current playlist.
"""
self.__client.play(songid)
@remoteAccess('Error during control access.')
def pause(self):
"""
Pause the currently playing song.
"""
self.__client.pause(1)
@remoteAccess('Error during control access.')
def unpause(self):
"""
Unpause the currently playing song.
"""
self.__client.pause(0)
@remoteAccess('Error during control access.')
def stop(self):
"""
Stop the currently playing song.
"""
self.__client.stop()
@remoteAccess('Error during control access.')
def previous(self):
"""
Jump to the previous song in the playlist.
"""
self.__client.previous()
@remoteAccess('Error during control access.')
def next(self):
"""
Jump to the next song in the playlist.
"""
self.__client.next()
@remoteAccess('Error during control access.')
def set_volume(self, volume):
"""
Raise the music volume 10%.
"""
self.__client.setvol(volume)
@remoteAccess('Error removing item from playlist.')
def delete(self, songid):
"""
Delete a song from the current playlist.
Args:
songid: The song id in the current playlist to be deleted.
"""
try:
self.__client.delete(songid)
except CommandError:
#TODO Error handling
self.logger.exception("delete: CommandError")
示例6: MPDClient
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import setvol [as 别名]
from mpd import MPDClient
import time
# Connect Client #
client = MPDClient()
client.idletimeout = None
client.connect("localhost", 6600)
# Connect Client #
# Play #
client.status()
client.clear()
client.add("http://gffstream.ic.llnwd.net/stream/gffstream_mp3_w62a")
client.setvol(100)
client.play()
#time.sleep(300)
# Play #
# Stop #
#client.setvol(90)
#time.sleep(1.5)
#client.setvol(80)
#time.sleep(1.5)
#client.setvol(70)
#time.sleep(1.5)
#client.setvol(60)
#time.sleep(1.5)
#client.setvol(50)
#time.sleep(1.5)
#client.setvol(40)
#client.stop()
示例7: __init__
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import setvol [as 别名]
class TestBookmark:
def __init__(self):
#Fill there
self.testHost="localhost"
self.testPort=6600
self.testPass=None
self.testMotif=""
self.testField="file"
#Test songs must last more than 30s
self.song1="Jacques Brel/Album/11-Vierson.mp3"
self.song2="Cream/Cream - 2000 - The Millenium Collection - [V2]/07 - Tales Of Brave Ulysses.mp3"
#Before every test
def setup(self):
print "Connection to MPD .........",
self.client=MPDClient()
self.client.connect(self.testHost,self.testPort)
if self.testPass:
self.client.password(self.testPass)
print "Done"
self.client.clear()
self.volume=self.client.status()['volume']
self.client.setvol(0)
self.client.consume(0)
self.client.sticker_set('song', self.song1,
'last_up', 0)
self.client.sticker_set('song', self.song2,
'last_up', 0)
self.launch_bookmark()
#After every test
def teardown(self):
self.client.clear()
self.client.setvol(self.volume)
print "Disconect MPD .............",
self.client.disconnect()
print "Done"
self.kill_bookmark()
def launch_bookmark(self):
self._thread=threading.Thread(None, MPDBookmark, None, (),
{'host':self.testHost,
'port':self.testPort,
'password':self.testPass,
'motif':self.testMotif,
'field':self.testField})
self._thread.start()
print "Launch done"
def kill_bookmark(self):
self._thread._Thread__stop()
print "kill done"
def test_Version(self):
print "Version : ",
print self.client.mpd_version
#assert self.client.mpd_version=='0.18.0'
def test_cold_start(self):
print "cold start"
self.client.add(self.song1)
Ti=time.time()
self.client.play()
time.sleep(6)
self.client.pause()
Tf=time.time()
time.sleep(2)#Wait a bit the writing in MPD sticker
read_time=int(self.client.sticker_get('song', self.song1, 'last_up'))
real_time=Tf-Ti
print "abs(read_time-real_time) ",
print "read time :", read_time,
print "real time :", real_time,
print " = ",abs(read_time-real_time)
assert abs(read_time-6)<=2.
assert abs(read_time-real_time)<=2.
def test_pause(self):
p1=5
p2=2
print "pause"
self.client.add(self.song1)
self.client.play()
time.sleep(p1)
self.client.pause()
time.sleep(2)
self.client.play()
time.sleep(p2)
self.client.stop()
time.sleep(2)#Wait a bit the writing in MPD sticker
read_time=int(self.client.sticker_get('song', self.song1, 'last_up'))
print read_time, "vs", p1+p2
assert abs(read_time-(p1+p2))<=2.
#.........这里部分代码省略.........
示例8: myMPD
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import setvol [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
示例9: add_weather_tracks
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import setvol [as 别名]
status = client.status()
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()
示例10: int
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import setvol [as 别名]
try:
print "Now Playing: %s - %s" % (song['artist'], song['title'])
except KeyError:
pass
result = re.search(r'VOLUME (\S+)', sys.argv[4])
if result:
current_volume = int(client.status()['volume'])
new_volume = result.groups()[0]
if new_volume[0] == '+':
new_volume = int(new_volume[1:])
if new_volume + current_volume > 100:
client.setvol(100)
else:
client.setvol(current_volume + new_volume)
elif new_volume[0] == '-':
new_volume = int(new_volume[1:])
if current_volume - new_volume < 0:
client.setvol(0)
else:
client.setvol(current_volume - new_volume)
else:
new_volume = int(new_volume)
if new_volume < 0:
client.setvol(0)
示例11: __init__
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import setvol [as 别名]
class Audio:
"""class representing a single player connected to one mpd instance"""
def __init__(self, config):
self.pid = config["id"]
self.name = config.get("name", "")
self.host = config["host"]
self.port = config.get("port", 6600)
self.password = config.get("password")
self.list_mode = config.get("list_mode", False)
self.playlist_folder = config.get("playlist_folder", '/')
self.playlists = {}
self.current = {}
self.next_song = {}
self.status = {}
self.outputs = {}
self.client = MPDClient()
self.connected = self.mpd_connect()
if self.connected:
if self.list_mode:
if 'shared' in self.list_mode:
playlists = self.client.lsinfo(self.playlist_folder)
for pls in playlists:
plsid = pls.get("playlist","")
if len(plsid) > 0:
try:
self.playlists['shared'].append((plsid,
'shd'+plsid))
except KeyError:
self.playlists['shared'] = []
self.playlists['shared'].append((plsid,
'shd_'+plsid))
if 'server' in self.list_mode:
playlists = self.client.lsinfo(self.playlist_folder)
for pls in playlists:
plsid = pls.get("playlist","")
if len(plsid) > 0:
try:
self.playlists['server'].append((plsid,
'srv_'+plsid))
except KeyError:
self.playlists['server'] = []
self.playlists['server'].append((plsid,
'srv_'+plsid))
self.update_data()
def mpd_connect(self):
"""connect to mpd service"""
try:
self.client.connect(self.host, self.port)
except socket.error:
return False
return True
def mpd_reconnect(self):
"""reconnect to mpd service"""
self.client.disconnect()
self.connected = self.mpd_connect()
def update_data(self):
"""update data from mpd service"""
if self.connected:
try:
status = self.client.status()
self.status = dict([
('state',status.get('state','stop')),
('time',status.get('time', '0:000')),
('volume',status.get('volume', 0))
])
self.current = self.client.currentsong()
next_song_id = status.get('nextsong', -1)
try:
self.next_song = self.client.playlistinfo(next_song_id)[0]
except (CommandError, IndexError):
self.next_song = {}
_decode_utf8(self.current)
_decode_utf8(self.next_song)
self.outputs = self.client.outputs()
except ConnectionError:
self.mpd_reconnect()
def ctrl(self, action):
"""execute a mpd command"""
if self.connected:
if action == 'ply':
self.client.play()
elif action == 'pse':
self.client.pause()
elif action == 'vup':
status = self.client.status()
volume = int(status.get('volume', 0))
try:
self.client.setvol(min(volume + _VOLUME_STEP, 100))
except CommandError:
pass
elif action == 'vdn':
status = self.client.status()
volume = int(status.get('volume', 0))
try:
self.client.setvol(max(volume - _VOLUME_STEP, 0))
except CommandError:
#.........这里部分代码省略.........
示例12: int
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import setvol [as 别名]
print 'Press Ctrl-C to quit.'
# --------------------------
# Main Loop
# --------------------------
while True:
stats = client.fetch_status() # Get the results of the last request
# If we've got anything to do from the LCD panel.
while not action_queue.empty():
action = action_queue.get(False)
if action == ACTION_VOLUME_UP:
newvol = int(stats['volume']) + 5
if newvol > 100:
newvol = 100
client.setvol(newvol)
elif action == ACTION_VOLUME_DOWN:
newvol = int(stats['volume']) - 5
if newvol < 0:
newvol = 0
client.setvol(newvol)
elif action == ACTION_NEXT:
client.next()
elif action == ACTION_PREV:
client.previous()
elif action == ACTION_REWIND:
try:
client.seek(stats['song'],0)
except:
print("Can't seek to beginning!")
elif action == ACTION_PLAYPAUSE:
示例13: adc0
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import setvol [as 别名]
print "trim_pot:", trim_pot
print "pot_adjust:", pot_adjust
print "last_read", last_read
if ( pot_adjust > tolerance ):
trim_pot_changed = True
if DEBUG:
print "trim_pot_changed", trim_pot_changed
if ( trim_pot_changed ):
set_volume = trim_pot / 10.24 # convert 10bit adc0 (0-1024) trim pot read into 0-100 volume level
mapped = (set_volume / 100.0) * (100 - minvol)
set_volume = int(round(minvol + mapped))
print 'Volume = {volume}%' .format(volume = set_volume)
# set_vol_cmd = 'sudo amixer cset numid=1 -- {volume}% > /dev/null' .format(volume = set_volume)
# os.system(set_vol_cmd) # set volume
client.setvol(set_volume)
if DEBUG:
print "set_volume", set_volume
print "tri_pot_changed", set_volume
# save the potentiometer reading for the next loop
last_read = trim_pot
# hang out and do nothing for a half second
time.sleep(0.5)
示例14: __init__
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import setvol [as 别名]
#.........这里部分代码省略.........
elif (len(word) >= 2):
lst.append(word[0].upper() + word[1:]) # Add to list
else:
lst.append(word[0].upper()) # Add to list
# Return joined list
return " ".join(lst)
# This function is called by buttons to give commands to MPD
def commands(self, command):
if (command == 'PLAY'):
if (self.data['state'] == 1):
self.cmd_client.pause(1)
else:
self.cmd_client.play()
elif (command == 'STOP'):
self.cmd_client.stop()
elif (command == 'NEXT'):
self.cmd_client.next()
elif (command == 'PREV'):
self.cmd_client.previous()
elif (command == 'VDN'):
# Get volume value
vol = self.data['volume'] - 5
if (vol < 0):
vol = 0
self.cmd_client.setvol(vol)
elif (command == 'VUP'):
# Get volume value
vol = self.data['volume'] + 5
if (vol > 100):
vol = 100
self.cmd_client.setvol(vol)
# Function for updating data
# Returns which option has been changed (shuffle - 0, repeat all - 1, repeat single - 2, nothing changed - -1)
def updateData(self):
# Nothing has changed so far
changed = -1
# Fetch volume
try:
self.data['volume'] = int(self.client.status()['volume'])
except KeyError:
self.data['volume'] = 0
# Get state
try:
state = self.client.status()['state']
except KeyError:
state = ''
# Get station
try:
station = self.client.currentsong()['name']
except KeyError:
示例15: MPDClient
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import setvol [as 别名]
#!/usr/bin/env python
from mpd import MPDClient
import time
maxVolume = 75
time_to_max_volume = 0.5 # TODO: Configure
mpd_host = '192.168.178.50'
mpd_port = 6600
client = MPDClient()
client.connect(mpd_host, mpd_port)
client.setvol(0)
client.playid(0)
# Push to maxVolume in time_to_max_volume
steps = 70 / (time_to_max_volume * 60)
counter = 0
while counter < maxVolume:
client.setvol(int(counter))
time.sleep(1)
counter += steps
client.close()