当前位置: 首页>>代码示例>>Python>>正文


Python SoCo.play方法代码示例

本文整理汇总了Python中soco.SoCo.play方法的典型用法代码示例。如果您正苦于以下问题:Python SoCo.play方法的具体用法?Python SoCo.play怎么用?Python SoCo.play使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在soco.SoCo的用法示例。


在下文中一共展示了SoCo.play方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: CommonHardwareSoco

# 需要导入模块: from soco import SoCo [as 别名]
# 或者: from soco.SoCo import play [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()
开发者ID:MediaKraken,项目名称:MediaKraken_Deployment,代码行数:28,代码来源:common_hardware_soco.py

示例2: playpause

# 需要导入模块: from soco import SoCo [as 别名]
# 或者: from soco.SoCo import play [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()
开发者ID:bgriffiths,项目名称:ledsign,代码行数:11,代码来源:sonos.py

示例3: sexy_time

# 需要导入模块: from soco import SoCo [as 别名]
# 或者: from soco.SoCo import play [as 别名]
def sexy_time():
    # connect to the Sonos
    sonos = SoCo(SONOS_IP)

    # connect to Philips Hue Bridge
    hue = Bridge(ip=HUE_IP,
                 username=HUE_USERNAME)

    # get queue
    queue = sonos.get_queue()

    # if we:
    # * already have a queue
    # * music is playing
    # * we are already playing a queue that begins with "Let's Get It On"
    # ...then skip to the next track

    if len(queue) > 0 and \
       sonos.get_current_transport_info()['current_transport_state'] == "PLAYING" and \
       queue[0].title == SEXY_TIME_FIRST_TRACK:
        sonos.next()

    # else, intitiate a fresh Sexy Time

    else:
        # clear Sonos queue
        sonos.clear_queue()

        # turn off shuffle and repeat
        sonos.play_mode = 'NORMAL'

        # set volume
        sonos.volume = 45

        # play Sexy Time playlist

        playlist = get_sonos_playlist(sonos, SEXY_TIME_PLAYLIST_NAME)

        if playlist:
            sonos.add_to_queue(playlist)
            sonos.play()

        # dim the lights (bri out of 254) over the pre-defined amount of time

        command = {
            'transitiontime': (SEXY_TIME_DIMMER_SECONDS * 10),
            'on': True,
            'bri': SEXY_TIME_DIMMER_BRIGHTNESS
        }

        hue.set_light(1, command)

    return jsonify(status="success")
开发者ID:andrewladd,项目名称:auto-awesome,代码行数:55,代码来源:server.py

示例4: sonos_play

# 需要导入模块: from soco import SoCo [as 别名]
# 或者: from soco.SoCo import play [as 别名]
    def sonos_play(self):
        """Afspeellijst, <play> button, afspelen of doorgaan na een pauze.
        """
        
        # pagina laden voor als antwoord terug aan de server
        h = queuebeheer_temp.sonos_play()
                
        ## sonos, afspelen
        sonos = SoCo(COORDINATOR)
        sonos.play()

        return h
开发者ID:dirk2011,项目名称:mymc_git,代码行数:14,代码来源:queuebeheer.py

示例5: playTheme

# 需要导入模块: from soco import SoCo [as 别名]
# 或者: from soco.SoCo import play [as 别名]
def playTheme(data, cur, themes, sonosPlayer):
    if data['hw'] in themes.keys() and getLastAction(data, cur) == 'remove':
        from soco import SoCo
        sonos = SoCo(sonosPlayer)
        if sonos.get_current_transport_info() == 'PLAYING':
            return '';
        sonos.unjoin();
        sonos.play_uri(themes[data['hw']])
        sonos.volume = 20;
        if sonos.get_current_transport_info() == 'PLAYING':
            return '';    
        sonos.play()
        syslog.syslog('Playing theme for: ' + data['hw'])
开发者ID:Hexren,项目名称:dhcpThemeSongs,代码行数:15,代码来源:dhcpevent.py

示例6: playTheme

# 需要导入模块: from soco import SoCo [as 别名]
# 或者: from soco.SoCo import play [as 别名]
def playTheme(themes, sonosPlayer):
    sonos = SoCo(sonosPlayer)
    #syslog.syslog('%s' % str(sonos.get_current_track_info()))
    #return '';
    if playerPlays(sonos):
        syslog.syslog('Already playing')
        return '';
    sonos.unjoin()
    sonos.clear_queue()
    sonos.add_uri_to_queue(themes['closer'])
    sonos.play_mode = 'REPEAT_ALL'
    syslog.syslog('%s' % sonos.play_mode)
    sonos.volume = 5;    
    if playerPlays(sonos):
        return '';    
    sonos.play()
    syslog.syslog('Playing Closer')
开发者ID:Hexren,项目名称:dhcpThemeSongs,代码行数:19,代码来源:playCloser.py

示例7: sonos

# 需要导入模块: from soco import SoCo [as 别名]
# 或者: from soco.SoCo import play [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"
开发者ID:qwango,项目名称:lightwaverfserver,代码行数:19,代码来源:lightwaverfserver.py

示例8: play

# 需要导入模块: from soco import SoCo [as 别名]
# 或者: from soco.SoCo import play [as 别名]
    def play(self):
        self.logger.info('Playing zones...')
        for ip in self._ZONE_IPS:
            device = SoCo(ip)
	    self.logger.debug('Playing zone at %s', ip)
	    if not device.play():
                self.logger.error('Unable to play zone at %s', ip)
		return False
	self.logger.info('All zones playing.')
        return True
开发者ID:Cushychicken,项目名称:blockclock,代码行数:12,代码来源:blockclock.py

示例9: arriving_home

# 需要导入模块: from soco import SoCo [as 别名]
# 或者: from soco.SoCo import play [as 别名]
def arriving_home():
    # connect to Philips Hue Bridge
    hue = Bridge(ip=HUE_IP,
                 username=HUE_USERNAME)

    # set the lights to approximately 80% over 3 seconds

    command = {
        'transitiontime': 30,
        'on': True,
        'bri': 203
    }

    hue.set_light(1, command)

    # connect to the Sonos
    sonos = SoCo(SONOS_IP)

    # clear the queue
    sonos.clear_queue()

    # set volume
    sonos.volume = 25

    # play Arriving Home playlist

    playlist = get_sonos_playlist(sonos, ARRIVING_HOME_PLAYLIST_NAME)
    print playlist

    if playlist:
        sonos.add_to_queue(playlist)

        # turn on shuffle, turn off repeat
        sonos.play_mode = 'SHUFFLE_NOREPEAT'

        # play
        sonos.play()

        # we're in shuffle mode, but the first track is always the same
        sonos.next()

    return jsonify(status="success")
开发者ID:andrewladd,项目名称:auto-awesome,代码行数:44,代码来源:server.py

示例10: arriving_home

# 需要导入模块: from soco import SoCo [as 别名]
# 或者: from soco.SoCo import play [as 别名]
def arriving_home():
    # connect to Philips Hue Bridge
    hue = Bridge(ip=HUE_IP,
                 username=HUE_USERNAME)

    # set the lights to appropriate brightness over appropriate time

    command = {
        'transitiontime': (ARRIVING_HOME_DIMMER_SECONDS * 10),
        'on': True,
        'bri': ARRIVING_HOME_DIMMER_BRIGHTNESS
    }

    hue.set_light(ARRIVING_HOME_LIGHTS, command)

    # connect to the Sonos
    sonos = SoCo(SONOS_IP)

    # clear the queue
    sonos.clear_queue()

    # set volume
    sonos.volume = ARRIVING_HOME_VOLUME

    # play Arriving Home playlist
    playlist = get_sonos_playlist(sonos, ARRIVING_HOME_PLAYLIST_NAME)

    if playlist:
        sonos.add_to_queue(playlist)

        # turn on shuffle, turn off repeat
        sonos.play_mode = 'SHUFFLE_NOREPEAT'

        # play
        sonos.play()

        # we're in shuffle mode, but the first track is always the same
        sonos.next()

    return jsonify(status="success")
开发者ID:mrkipling,项目名称:auto-awesome,代码行数:42,代码来源:server.py

示例11: party

# 需要导入模块: from soco import SoCo [as 别名]
# 或者: from soco.SoCo import play [as 别名]
def party():
    # connect to the Sonos
    sonos = SoCo(SONOS_IP)

    # get queue
    queue = sonos.get_queue()

    # if we:
    # * already have a queue
    # * music is playing
    # ...then skip to the next track

    if len(queue) > 0 and sonos.get_current_transport_info()['current_transport_state'] == "PLAYING":
        sonos.next()

    # else, intitiate a fresh Party Time

    else:
        # clear Sonos queue
        sonos.clear_queue()

        # turn on shuffle, turn off repeat
        sonos.play_mode = 'SHUFFLE_NOREPEAT'

        # set volume
        sonos.volume = 45

        # play Party playlist

        playlist = get_sonos_playlist(sonos, PARTY_TIME_PLAYLIST_NAME)

        if playlist:
            sonos.add_to_queue(playlist)
            sonos.play()

    return jsonify(status="success")
开发者ID:andrewladd,项目名称:auto-awesome,代码行数:38,代码来源:server.py

示例12: SoCo

# 需要导入模块: from soco import SoCo [as 别名]
# 或者: from soco.SoCo import play [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()
开发者ID:SaschaJohn,项目名称:smartPad,代码行数:21,代码来源:soc.py

示例13: connect

# 需要导入模块: from soco import SoCo [as 别名]
# 或者: from soco.SoCo import play [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
开发者ID:pierreca,项目名称:Tyler,代码行数:70,代码来源:sonos.py

示例14: __init__

# 需要导入模块: from soco import SoCo [as 别名]
# 或者: from soco.SoCo import play [as 别名]
class SonosStateMc:

    def __init__(self, sonos_ip):
        self.state_var = SONOS_IDLE
        self.sonos_ip = sonos_ip
        self.sonos = SoCo(self.sonos_ip)
        self.vol_to_return_to = self.sonos.volume
        self.time_out = 0
        self.retry_count = 0
        self.state_entry_time = time.time()
        self.prev_state = SONOS_IDLE
        self.logged_idle = False
        self.sound_uri = ""
        self.play_pending = False
        self.abort_pending = False
        self.play_volume = 30
        self.track_info_to_return_to = None
        self.state_info_to_return_to = None

    def execCmd(self, cmd, param, meta):
        self.state_var = SONOS_IDLE
        self.play_pending = False
        self.abort_pending = False
        if cmd.lower() == "play":
            if param == "":
                self.sonos.play()
            else:
                self.sonos.play_uri(param, meta)
        elif cmd.lower() == "stop":
            self.sonos.stop()
        elif cmd.lower() == "volup":
            self.sonos.volume = self.sonos.volume + 10
        elif cmd.lower() == "voldown":
            self.sonos.volume = self.sonos.volume - 10

    def musicStop(self):
        self.state_var = SONOS_IDLE
        self.play_pending = False
        self.abort_pending = False
        self.sonos.stop()

    def getDeviceName(self):
        return self.sonos.player_name

    def getFavouriteRadioStations(self):
        return self.sonos.get_favorite_radio_stations(0,6)

    def playSound(self, soundUri, playVolume):
        self.sound_uri = soundUri
        self.play_volume = playVolume
        self.play_pending = True

    def elapsedTime(self):
        return time.time() - self.state_entry_time

    def changeState(self, newState):
        self.prev_state = self.state_var
        self.state_var = newState
        self.state_entry_time = time.time()

    def restore(self):
        self.sonos.volume = self.vol_to_return_to
        # Check for radio or similar
        # Currently this is done by checking the track duration
        if self.track_info_to_return_to["duration"] == "0:00:00":
            # Handle playing from the radio or similar
            self.sonos.play_uri(self.track_info_to_return_to["uri"])
        else:
            # Handle continuation of playing a track from the queue
            try:
                queue_pos = int(self.track_info_to_return_to["playlist_position"]) - 1
            except:
                return
            self.sonos.play_from_queue(queue_pos)
            self.sonos.seek(self.track_info_to_return_to["position"])
        if self.state_info_to_return_to["current_transport_state"] == "PAUSED_PLAYBACK" or self.state_info_to_return_to["current_transport_state"] == "STOPPED":
            self.changeState(SONOS_RESTORE_PEND)
            self.time_out = 3
            self.retry_count = 2
        else:
            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:
#.........这里部分代码省略.........
开发者ID:robdobsn,项目名称:RdHomeServer,代码行数:103,代码来源:SonosDevice.py

示例15: main

# 需要导入模块: from soco import SoCo [as 别名]
# 或者: from soco.SoCo import play [as 别名]
import re
from settings import *
from soco import SonosDiscovery, SoCo
import speaker_info


def main():
    si = {}
    try:
        si = speaker_info.load_speaker_info()
    except Exception, e:
        speaker_info.refresh_speaker_info()
        si = speaker_info.load_speaker_info()

    for (ip, speaker) in si.items():
        if re.search(PRIMARY_ZONE, speaker.get("zone_name", ""), re.I) is not None:
            s = SoCo(ip)
            speaker_info.store_volume(ip, s.volume())
            s.volume(AIRPLAY_SONOS_VOLUME)
            s.switch_to_line_in()
            s.play()


if __name__ == "__main__":
    main()
开发者ID:sbma44,项目名称:shairport,代码行数:27,代码来源:engage.py


注:本文中的soco.SoCo.play方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。