duncan3dc\Sonos\Controller::getStateDetails PHP Method

getStateDetails() public method

Get attributes about the currently active track in the queue.
public getStateDetails ( ) : State
return State Track data containing the following elements
    public function getStateDetails()
    {
        $data = $this->soap("AVTransport", "GetPositionInfo");
        # Check for line in mode
        if ($data["TrackMetaData"] === "NOT_IMPLEMENTED") {
            $state = new State($data["TrackURI"]);
            $state->stream = "Line-In";
            return $state;
        }
        # Check for an empty queue
        if (!$data["TrackMetaData"]) {
            return new State();
        }
        $parser = new XmlParser($data["TrackMetaData"]);
        $state = State::createFromXml($parser->getTag("item"), $this);
        if ((string) $parser->getTag("streamContent")) {
            $info = $this->getMediaInfo();
            if (!($state->stream = (string) (new XmlParser($info["CurrentURIMetaData"]))->getTag("title"))) {
                $state->stream = (string) $parser->getTag("title");
            }
        }
        $state->queueNumber = (int) $data["Track"];
        $state->duration = $data["TrackDuration"];
        $state->position = $data["RelTime"];
        # If we have a queue number, it'll be one-based, rather than zero-based, so convert it
        if ($state->queueNumber > 0) {
            $state->queueNumber--;
        }
        return $state;
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Get the current playing attributes (stream/position/etc).
  *
  * @param Controller $controller The Controller to grab the state of
  *
  * @return static
  */
 protected function getState(Controller $controller)
 {
     $this->state = $controller->getState();
     $details = $controller->getStateDetails();
     $this->track = $details->queueNumber;
     $this->position = $details->position;
     return $this;
 }