From 18eb64c61ff1dc595c88b5331ec57ec88cac0ad0 Mon Sep 17 00:00:00 2001 From: Vaalyn Date: Thu, 8 Jul 2021 21:02:19 +0200 Subject: [PATCH] Restore missing annotateNextSong fixes from cpeter1207 (#4373) --- src/Radio/AutoDJ.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Radio/AutoDJ.php b/src/Radio/AutoDJ.php index a7da7fb74..83cfb1dd5 100644 --- a/src/Radio/AutoDJ.php +++ b/src/Radio/AutoDJ.php @@ -94,14 +94,26 @@ class AutoDJ return $this->annotateNextSong($station, $asAutoDj, $iteration + 1); } + // Build adjusted "now" based on the currently playing song before annotating up the next one + $adjustedNow = $this->getAdjustedNow( + $station, + $this->getNowFromCurrentSong($station), + $queueRow->getDuration() + ); + $event = new AnnotateNextSong($queueRow, $asAutoDj); $this->dispatcher->dispatch($event); + + // Refill station queue while taking into context that LS queues songs 40s before they are played + $this->buildQueue($station, true, $adjustedNow); + return $event->buildAnnotations(); } public function buildQueue( Entity\Station $station, - bool $force = false + bool $force = false, + CarbonInterface $nowOverride = null ): void { $lock = $this->lockFactory->createAndAcquireLock( resource: 'autodj_queue_' . $station->getId(), @@ -125,7 +137,7 @@ class AutoDJ ); // Adjust "now" time from current queue. - $now = $this->getNowFromCurrentSong($station); + $now = $nowOverride ?? $this->getNowFromCurrentSong($station); $maxQueueLength = $station->getBackendConfig()->getAutoDjQueueLength(); if ($maxQueueLength < 1) {