public function interrupt(UriInterface $track, $volume = null)
{
/**
* Ensure the track has been generated.
* If it's a TextToSpeech then the api call is done lazily when the uri is required.
* So it's better to do this here, rather than after the controller has been paused.
*/
$track->getUri();
$state = $this->exportState();
# Replace the current queue with the passed track
$this->useQueue()->getQueue()->clear()->addTrack($track);
# Ensure repeat is not on, or else this track would just play indefinitely
$this->setRepeat(false);
# If a volume was passed then use it
if ($volume !== null) {
$this->setVolume($volume);
}
# Play the track
$this->play();
# Sleep first so that the track has a chance to at least start
sleep(1);
# Wait for the track to finish
while ($this->getState() === self::STATE_PLAYING) {
usleep(500000);
}
# Restore the previous state of this controller
$this->restoreState($state);
return $this;
}