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


Python SoCo.seek方法代码示例

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


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

示例1: __init__

# 需要导入模块: from soco import SoCo [as 别名]
# 或者: from soco.SoCo import seek [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


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