本文整理汇总了Python中soco.SoCo.pause方法的典型用法代码示例。如果您正苦于以下问题:Python SoCo.pause方法的具体用法?Python SoCo.pause怎么用?Python SoCo.pause使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类soco.SoCo
的用法示例。
在下文中一共展示了SoCo.pause方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from soco import SoCo [as 别名]
# 或者: from soco.SoCo import pause [as 别名]
class Sonos:
def __init__(self, ip):
self.sonos = SoCo(ip)
self.sonos.volume = 60
def playJason(self):
self.sonos.play_uri("x-sonos-spotify:spotify%3atrack%3a6g6A7qNhTfUgOSH7ROOxTD?sid=12&flags=32")
time.sleep(1)
self.sonos.pause()
def randomKatyPerrySong(self):
darkHorse = 'x-sonos-spotify:spotify%3atrack%3a5jrdCoLpJSvHHorevXBATy?sid=12&flags=32'
firework = 'x-sonos-spotify:spotify%3atrack%3a4lCv7b86sLynZbXhfScfm2?sid=12&flags=32'
roar = 'x-sonos-spotify:spotify%3atrack%3a3XSczvk4MRteOw4Yx3lqMU?sid=12&flags=32'
birthday = 'x-sonos-spotify:spotify%3atrack%3a2xLOMHjkOK8nzxJ4r6yOKR?sid=12&flags=32'
californiaGurls = 'x-sonos-spotify:spotify%3atrack%3a6tS3XVuOyu10897O3ae7bi?sid=12&flags=32'
teenageDream = 'x-sonos-spotify:spotify%3atrack%3a55qBw1900pZKfXJ6Q9A2Lc?sid=12&flags=32'
lastFridayNight = 'x-sonos-spotify:spotify%3atrack%3a455AfCsOhhLPRc68sE01D8?sid=12&flags=32'
peacock = 'x-sonos-spotify:spotify%3atrack%3a3y3Hucw52QpjtHUeOKTkaO?sid=12&flags=32'
et = 'x-sonos-spotify:spotify%3atrack%3a4kkeuVl6gF3RMqE4Nn5W3E?sid=12&flags=32'
songs = [darkHorse, firework, roar, birthday, californiaGurls, teenageDream, lastFridayNight, peacock, et]
chosen_song = random.choice(songs)
return chosen_song
def playKatyPerry(self):
self.playJason()
self.sonos.play_uri(self.randomKatyPerrySong())
# set Katy Perry duration here (in seconds)
time.sleep(10)
self.sonos.pause()
示例2: CommonHardwareSoco
# 需要导入模块: from soco import SoCo [as 别名]
# 或者: from soco.SoCo import pause [as 别名]
class CommonHardwareSoco(object):
"""
Class for Sonos
"""
def __init__(self, ip_addr):
self.soco_inst = SoCo(ip_addr)
def com_hardware_soco_name(self):
return self.soco_inst.player_name
def com_hardware_soco_volume(self, set_volume):
self.soco_inst.volume = set_volume
def com_hardware_soco_light_status(self, light_status):
self.soco_inst.status_light = light_status
def com_hardware_soco_play_url(self, url):
self.soco_inst.play_uri(url)
def com_hardware_soco_pause(self):
self.soco_inst.pause()
def com_hardware_soco_play(self):
# Play a stopped or paused track
self.soco_inst.play()
示例3: playpause
# 需要导入模块: from soco import SoCo [as 别名]
# 或者: from soco.SoCo import pause [as 别名]
def playpause(self):
my_zone = SoCo('192.168.1.19')
status = my_zone.get_current_transport_info()
if(status['current_transport_state'] == "PLAYING"):
print('Sonos - Pause')
my_zone.pause()
else:
print('Sonos- Play')
my_zone.play()
示例4: tune
# 需要导入模块: from soco import SoCo [as 别名]
# 或者: from soco.SoCo import pause [as 别名]
def tune():
station = request.args.get('station')
target = request.args.get('target')
sonos = SoCo(target)
sonos.pause()
if station == 'eldoradio':
sonos.play_uri('x-rincon-mp3radio://sender.eldoradio.de:8000/high')
elif station == 'xfm':
sonos.play_uri('x-rincon-mp3radio://live64.917xfm.de')
elif station == 'wdr5':
sonos.play_uri('x-rincon-mp3radio://wdr-5.akacast.akamaistream.net/7/41/119439/v1/gnl.akacast.akamaistream.net/wdr-5')
return 'Ok'
示例5: sonos_pause
# 需要导入模块: from soco import SoCo [as 别名]
# 或者: from soco.SoCo import pause [as 别名]
def sonos_pause(self):
"""Afspeellijst, <pause> button, afspelen pauzeren.
"""
# pagina laden voor als antwoord terug aan de server
h = queuebeheer_temp.sonos_pause()
## sonos, afspelen pauzeren
sonos = SoCo(COORDINATOR)
sonos.pause()
return h
示例6: sonos
# 需要导入模块: from soco import SoCo [as 别名]
# 或者: from soco.SoCo import pause [as 别名]
def sonos(command, volume=-1):
s = SoCo(app.config['SONOS'])
try:
if command == 'play':
s.play()
elif command == 'pause':
s.pause()
elif command =='volume':
logging.info('Setting volume of Sonos to %d' % volume)
s.volume(volume)
elif command == 'next':
s.next()
elif command == 'previous':
s.previous()
return "OK"
except:
return "FAIL"
示例7: pause
# 需要导入模块: from soco import SoCo [as 别名]
# 或者: from soco.SoCo import pause [as 别名]
def pause(self):
self.logger.info('Pausing zones...')
for ip in self._ZONE_IPS:
device = SoCo(ip)
self.logger.debug('Pausing zone at %s', ip)
if not device.pause():
self.logger.error('Unable to pause zone at %s', ip)
return False
self.logger.info('All zones paused.')
return True
示例8: SoCo
# 需要导入模块: from soco import SoCo [as 别名]
# 或者: from soco.SoCo import pause [as 别名]
if __name__ == '__main__':
if (len(sys.argv) != 3):
print "Usage: sonoshell.py [speaker's IP] [cmd]"
print ""
print "Valid commands: play, pause, stop, next, previous, current, and partymode"
sys.exit()
speaker_ip = sys.argv[1]
cmd = sys.argv[2].lower()
sonos = SoCo(speaker_ip)
if (cmd == 'partymode'):
print sonos.partymode()
elif (cmd == 'play'):
print sonos.play()
elif (cmd == 'pause'):
print sonos.pause()
elif (cmd == 'stop'):
print sonos.stop()
elif (cmd == 'next'):
print sonos.next()
elif (cmd == 'previous'):
print sonos.previous()
elif (cmd == 'current'):
track = sonos.get_current_track_info()
print 'Current track: ' + track['artist'] + ' - ' + track['title'] + '. From album ' + track['album'] + '. This is track number ' + track['playlist_position'] + ' in the playlist. It is ' + track['duration'] + ' minutes long.'
else:
print "Valid commands: play, pause, stop, next, previous, current, and partymode"
示例9: SoCo
# 需要导入模块: from soco import SoCo [as 别名]
# 或者: from soco.SoCo import pause [as 别名]
from soco import SoCo
if __name__ == '__main__':
sonos = SoCo('192.168.178.37') # Pass in the IP of your Sonos speaker
# You could use the discover function instead, if you don't know the IP
# Pass in a URI to a media file to have it streamed through the Sonos
# speaker
sonos.play_uri(
'x-rincon-mp3radio://sender.eldoradio.de:8000/high')
track = sonos.get_current_track_info()
print track['title']
sonos.pause()
# Play a stopped or paused track
sonos.play()
示例10: connect
# 需要导入模块: from soco import SoCo [as 别名]
# 或者: from soco.SoCo import pause [as 别名]
class SonosController:
_device = None
def connect(self):
ips = []
while (len(ips) == 0):
print "No Sonos found"
sonos_devices = SonosDiscovery()
ips = sonos_devices.get_speaker_ips()
print "Found {0} device(s)".format(len(ips))
for ip in ips:
self._device = SoCo(ip)
zone_name = self._device.get_speaker_info()['zone_name']
print "IP of {0} is {1}".format(zone_name, ip)
def get_current_song(self):
if self._device == None:
self.connect()
now_playing = self._device.get_current_track_info()
return now_playing
def play_pandora_station(self, code):
if self._device == None:
self.connect()
PLAY_STATION_ACTION ='"urn:schemas-upnp-org:service:AVTransport:1#SetAVTransportURI"'
TRANSPORT_ENDPOINT = '/MediaRenderer/AVTransport/Control'
JOIN_RESPONSE = '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:SetAVTransportURIResponse xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"></u:SetAVTransportURIResponse></s:Body></s:Envelope>'
PLAY_STATION_BODY_TEMPLATE ='"<u:SetAVTransportURI xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><CurrentURI>pndrradio:{music_service_station_id}</CurrentURI><CurrentURIMetaData></CurrentURIMetaData></u:SetAVTransportURI></s:Body></s:Envelope>'
body = PLAY_STATION_BODY_TEMPLATE.format(music_service_station_id = code)
response = self._device.send_command(TRANSPORT_ENDPOINT, PLAY_STATION_ACTION, body)
if (response == JOIN_RESPONSE):
self._device.play()
return True
else:
return self._device.parse_error(response)
def pause(self):
if self._device == None:
connect()
try:
self._device.pause()
except:
print "Error trying to pause music: there is probably nothing playing right now."
return False
return True
def get_volume(self):
if self._device == None:
self.connect()
current_volume = self._device.volume()
return current_volume
def set_volume(self, volume):
if self._device == None:
self.connect()
result = self._device.volume(volume)
return result
示例11: stop
# 需要导入模块: from soco import SoCo [as 别名]
# 或者: from soco.SoCo import pause [as 别名]
def stop():
target = request.args.get('target')
sonos = SoCo(target)
sonos.pause()
return 'Ok'
示例12: __init__
# 需要导入模块: from soco import SoCo [as 别名]
# 或者: from soco.SoCo import pause [as 别名]
#.........这里部分代码省略.........
self.completed()
def abort(self):
self.logState("Aborting")
self.play_pending = False
self.abort_pending = True
self.restore()
def completed(self):
if self.abort_pending:
self.logState("Finished - ABORTED")
else:
self.logState("Finished - OK")
self.play_pending = False
self.abort_pending = False
self.changeState(SONOS_IDLE)
def logState(self, info):
if self.state_var == SONOS_IDLE:
if self.logged_idle:
return
self.logged_idle = True
else:
self.logged_idle = False
transp_info = self.sonos.get_current_transport_info()
track_info = self.sonos.get_current_track_info()
print ("StateNow: ", self.state_var, " PrevState", self.prev_state, " TimeOut: ", self.time_out, " Elapsed: ", self.elapsedTime(), "RetryCount: ", self.retry_count, " TranspState: ", transp_info["current_transport_state"], " PlaylistPos: ", track_info["playlist_position"], "Info: ", info)
def handleState(self):
# Handle idle
if self.state_var == SONOS_IDLE:
if self.play_pending:
self.changeState(SONOS_PLAY_REQ)
return
# Get current state information from sonos unit
transp_info = self.sonos.get_current_transport_info()
track_info = self.sonos.get_current_track_info()
cur_transp_state = transp_info['current_transport_state']
self.logState("handleStateEntry")
# Handle other states
if self.state_var == SONOS_PLAY_REQ:
self.vol_to_return_to = self.sonos.volume
self.track_info_to_return_to = track_info
self.state_info_to_return_to = transp_info
self.retry_count = 2
self.changeState(SONOS_PAUSE_TRY)
elif self.state_var == SONOS_PAUSE_TRY:
self.time_out = 10
if cur_transp_state == "PLAYING":
self.sonos.pause()
self.changeState(SONOS_PAUSE_PEND)
elif self.state_var == SONOS_PAUSE_PEND:
if cur_transp_state == "PAUSED_PLAYBACK" or cur_transp_state == "STOPPED":
self.changeState(SONOS_PLAY_START)
elif cur_transp_state == "PLAYING":
if self.elapsedTime() > self.time_out:
self.retry_count -= 1
if self.retry_count > 0:
self.changeState(SONOS_PAUSE_TRY)
else:
self.logState("FAILED TO PAUSE - STILL PLAYING")
self.abort()
else:
self.logState("FAILED TO PAUSE - UNKNOWN STATE")
self.abort()
elif self.state_var == SONOS_PLAY_START:
self.sonos.volume = self.play_volume
self.sonos.play_uri(self.sound_uri)
self.time_out = 30
self.retry_count = 2
self.changeState(SONOS_PLAY_PEND)
elif self.state_var == SONOS_PLAY_PEND:
if cur_transp_state == "PLAYING":
self.changeState(SONOS_PLAYING)
else:
if self.elapsedTime() > self.time_out:
self.retry_count -= 1
if self.retry_count > 0:
self.changeState(SONOS_PLAY_START)
else:
self.logState("FAILED TO PLAY")
self.abort()
elif self.state_var == SONOS_PLAYING:
if cur_transp_state == "PLAYING":
if self.elapsedTime() > self.time_out:
self.logState("FAILED TO FINISH PLAYING BEFORE TIMEOUT - TRACK TOO LONG?")
self.abort()
else:
self.restore()
elif self.state_var == SONOS_RESTORE_PEND:
if cur_transp_state == "PLAYING":
if self.state_info_to_return_to["current_transport_state"] == "PAUSED_PLAYBACK":
self.sonos.pause()
elif self.state_info_to_return_to["current_transport_state"] == "STOPPED":
self.sonos.stop()
self.completed()
else:
if self.elapsedTime() > self.time_out:
self.logState("FAILED TO RESTORE")
self.completed()
示例13: pause
# 需要导入模块: from soco import SoCo [as 别名]
# 或者: from soco.SoCo import pause [as 别名]
def pause(self):
for ip in self._ZONE_IPS:
device = SoCo(ip)
device.pause()
return True