public function restoreState(ControllerStateInterface $state): ControllerInterface
    {
        $queue = $this->getQueue();
        $queue->clear();
        $tracks = $state->getTracks();
        if (count($tracks) > 0) {
            $queue->addTracks($tracks);
        }

        if (count($tracks) > 0) {
            $this->selectTrack($state->getTrack());
            $this->seek($state->getPosition());
        }

        $this->setShuffle($state->getShuffle());
        $this->setRepeat($state->getRepeat());
        $this->setCrossfade($state->getCrossfade());

        if ($stream = $state->getStream()) {
            $this->useStream($stream);
        }

        $speakers = [];
        foreach ($this->getSpeakers() as $speaker) {
            $speakers[$speaker->getUuid()] = $speaker;
        }
        foreach ($state->getSpeakers() as $uuid => $volume) {
            if (array_key_exists($uuid, $speakers)) {
                $speakers[$uuid]->setVolume($volume);
            }
        }

        # If the exported state was playing then start it playing now
        if ($state->getState() === self::STATE_PLAYING) {
            $this->play();

        # If the exported state was stopped and we are playing then stop it now
        } elseif ($this->getState() === self::STATE_PLAYING) {
            $this->pause();
        }

        return $this;
    }
public function restoreState(ControllerStateInterface $state): ControllerInterface
    {
        $queue = $this->getQueue();
        $queue->clear();
        $tracks = $state->getTracks();
        if (count($tracks) > 0) {
            $queue->addTracks($tracks);
        }

        if (count($tracks) > 0) {
            $this->selectTrack($state->getTrack());
            $this->seek($state->getPosition());
        }

        $this->setShuffle($state->getShuffle());
        $this->setRepeat($state->getRepeat());
        $this->setCrossfade($state->getCrossfade());

        if ($stream = $state->getStream()) {
            $this->useStream($stream);
        }

        $speakers = [];
        foreach ($this->getSpeakers() as $speaker) {
            $speakers[$speaker->getUuid()] = $speaker;
        }
        foreach ($state->getSpeakers() as $uuid => $volume) {
            if (array_key_exists($uuid, $speakers)) {
                $speakers[$uuid]->setVolume($volume);
            }
        }

        # If the exported state was playing then start it playing now
        if ($state->getState() === self::STATE_PLAYING) {
            $this->play();

        # If the exported state was stopped and we are playing then stop it now
        } elseif ($this->getState() === self::STATE_PLAYING) {
            $this->pause();
        }

        return $this;
    }
public function restoreState ( ControllerStateInterface $ state ) : ControllerInterface { $ queue = $ this -> getQueue ( ) ; $ queue -> clear ( ) ; $ tracks = $ state -> getTracks ( ) ; if ( count ( $ tracks ) > 0 ) { $ queue -> addTracks ( $ tracks ) ; } if ( count ( $ tracks ) > 0 ) { $ this -> selectTrack ( $ state -> getTrack ( ) ) ; $ this -> seek ( $ state -> getPosition ( ) ) ; } $ this -> setShuffle ( $ state -> getShuffle ( ) ) ; $ this -> setRepeat ( $ state -> getRepeat ( ) ) ; $ this -> setCrossfade ( $ state -> getCrossfade ( ) ) ; if ( $ stream = $ state -> getStream ( ) ) { $ this -> useStream ( $ stream ) ; } $ speakers = [ ] ; foreach ( $ this -> getSpeakers ( ) as $ speaker ) { $ speakers [ $ speaker -> getUuid ( ) ] = $ speaker ; } foreach ( $ state -> getSpeakers ( ) as $ uuid => $ volume ) { if ( array_key_exists ( $ uuid , $ speakers ) ) { $ speakers [ $ uuid ] -> setVolume ( $ volume ) ; } } # If the exported state was playing then start it playing now if ( $ state -> getState ( ) === self :: STATE_PLAYING ) { $ this -> play ( ) ; # If the exported state was stopped and we are playing then stop it now } elseif ( $ this -> getState ( ) === self :: STATE_PLAYING ) { $ this -> pause ( ) ; } return $ this ; }
Restore the Controller to a previously exported state.

@param ControllerStateInterface $state The state to be restored

@return $this
Restore the Controller to a previously exported state .