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

Configure Feed

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

fix: Audio engine refactor issues + scrobbling (closes #432)

+24 -7
+24 -7
src/Javascript/UI/audio.ts
··· 104 104 105 105 106 106 function pauseScrobbleTimer() { 107 - if (this.scrobbleTimer) this.scrobbleTimer.pause() 107 + if (scrobbleTimer) scrobbleTimer.pause() 108 108 } 109 109 110 110 ··· 117 117 if (!audio.isConnected) return 118 118 119 119 const promise = audio.play() || Promise.resolve() 120 + const didPreload = audio.getAttribute("data-did-preload") === "true" 121 + const isPreload = audio.getAttribute("data-is-preload") === "true" 122 + 123 + if (didPreload && !isPreload) { 124 + audio.removeAttribute("data-did-preload") 125 + app.ports.audioDurationChange.send({ 126 + trackId: audio.id, 127 + duration: audio.duration, 128 + }) 129 + } 120 130 121 131 promise.catch((e) => { 122 132 if (!audio.isConnected) return /* The node was removed from the DOM, we can ignore this error */ ··· 159 169 const timestamp = Math.round(Date.now() / 1000) 160 170 const scrobbleTimeoutDuration = Math.min(240 + 0.5, duration / 1.95) 161 171 162 - if (this.scrobbleTimer) this.scrobbleTimer.stop() 172 + if (scrobbleTimer) scrobbleTimer.stop() 163 173 164 174 scrobbleTimer = new Timer({ 165 - onend: () => 175 + onend: () => { 176 + scrobbleTimer = undefined 166 177 app.ports.scrobble.send({ 167 178 duration: Math.round(duration), 168 179 timestamp, 169 180 trackId, 170 - }), 181 + }) 182 + } 171 183 }) 172 184 173 185 scrobbleTimer.start(scrobbleTimeoutDuration) ··· 262 274 263 275 264 276 function startScrobbleTimer() { 265 - if (this.scrobbleTimer) this.scrobbleTimer.start() 277 + if (scrobbleTimer) scrobbleTimer.start() 266 278 } 267 279 268 280 ··· 338 350 await items.reduce(async (acc: Promise<void>, item: EngineItem) => { 339 351 await acc 340 352 341 - if (existingNodes[item.trackId]) { 342 - existingNodes[item.trackId].setAttribute( 353 + const existingNode = existingNodes[item.trackId] 354 + 355 + if (existingNode) { 356 + const isPreload = existingNode.getAttribute("data-is-preload") 357 + if (isPreload === "true") existingNode.setAttribute("data-did-preload", "true") 358 + 359 + existingNode.setAttribute( 343 360 "data-is-preload", 344 361 item.isPreload ? "true" : "false", 345 362 )