A music player that connects to your cloud/distributed storage.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

chore: improve repeat audio

+22 -12
+4 -11
src/components/orchestrator/queue-audio/element.js
··· 150 150 const aud = now ? this.audio.state(now.id) : undefined; 151 151 152 152 if (aud?.hasEnded() && (await this.isLeader())) { 153 - // NOTE: Not sure yet if this is the best way to approach this. 154 - // The idea is that scrobblers would more easily pick this up, 155 - // as opposed to just resetting the audio. 156 - if (this.repeatShuffle?.repeat()) { 157 - const now = this.queue.now(); 158 - if (now) { 159 - await this.queue.add({ 160 - inFront: true, 161 - trackIds: [now.id], 162 - }); 163 - } 153 + if (this.repeatShuffle?.repeat() && now) { 154 + this.audio.seek({ audioId: now.id, currentTime: 0 }); 155 + this.audio.play({ audioId: now.id }); 156 + return; 164 157 } 165 158 166 159 await this.queue.shift();
+18 -1
src/components/orchestrator/scrobble-audio/element.js
··· 66 66 /** Whether `scrobble` has been called for the current track. */ 67 67 #scrobbled = false; 68 68 69 + /** Whether the current track has ended (used to detect restarts, e.g. repeat). */ 70 + #hadEnded = false; 71 + 69 72 // TIMER STATE 70 73 // Accumulates actual listening time (pauses don't count). 71 74 ··· 100 103 this.#nowPlayingSent = false; 101 104 this.#scrobbled = false; 102 105 this.#listenedMs = 0; 106 + this.#hadEnded = false; 103 107 } 104 108 105 109 if (!id) return; 106 110 107 111 const isPlaying = this.audio.state(id)?.isPlaying() ?? false; 112 + const hasEnded = this.audio.state(id)?.hasEnded() ?? false; 113 + 114 + // Detect same-track restart (e.g. repeat): the track ended and now plays again. 115 + if (this.#hadEnded && !hasEnded && isPlaying) { 116 + this.#stopTimer(); 117 + this.#startedAt = Date.now(); 118 + this.#nowPlayingSent = false; 119 + this.#scrobbled = false; 120 + this.#listenedMs = 0; 121 + this.#hadEnded = false; 122 + } 123 + 124 + if (hasEnded) this.#hadEnded = true; 108 125 109 126 if (isPlaying) { 110 127 this.#startTimer(); ··· 186 203 try { 187 204 await this.scrobble?.scrobble(track, startedAt); 188 205 } catch (err) { 189 - console.warn("scrobble: scrobble failed", err); 206 + console.warn("Scrobble failed", err); 190 207 this.#scrobbled = false; 191 208 } 192 209 }