{"record":{"id":"768e9b5e7604fa86","repo":"tonhowtf/omniget","slug":"player-spotify-sdk-failed-trying-youtube-fallback","errorCode":null,"errorMessage":"[player] Spotify SDK failed, trying YouTube fallback:","messagePattern":"\\[player\\] Spotify SDK failed, trying YouTube fallback:","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/lib/study-music/player-store.svelte.ts","lineNumber":1758,"sourceCode":"      console.info(\n        \"[player] spotify timing\",\n        {\n          stop_ms: Math.round(tStop - t0),\n          ready_ms: Math.round(tReady - tStop),\n          play_ms: Math.round(tPlay - tReady),\n          total_ms: Math.round(tPlay - t0),\n        },\n      );\n      this.saveQueueNow();\n      this.updateMediaSessionMetadata(track);\n      if (track.spotify_cover_url) {\n        void this.refreshDominantColorFromUrl(track.spotify_cover_url);\n      }\n      if (this._spotifyHeartbeatEnabled) this.startSpotifyHeartbeat();\n      return;\n    } catch (e) {\n      sdkErr = e;\n      console.warn(\"[player] Spotify SDK failed, trying YouTube fallback:\", e);\n    }\n\n    if (!this.spotifyFreeFallback || !this.audio) {\n      this.setError(classifyPlayerError(sdkErr ?? \"spotify sdk failed\", \"spotify\", track.id));\n      throw sdkErr ?? new Error(\"spotify sdk failed\");\n    }\n\n    try {\n      const url = await this.spotifyFreeFallback(track);\n      track.youtube_url = url;\n      this.audio.src = url;\n      await this.audio.play();\n      this.ensureEqGraph();\n      this.saveQueueNow();\n      this.updateMediaSessionMetadata(track);\n    } catch (e) {\n      this.setError(classifyPlayerError(e, \"spotify\", track.id));\n      throw e;","sourceCodeStart":1740,"sourceCodeEnd":1776,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src/lib/study-music/player-store.svelte.ts#L1740-L1776","documentation":"Logged when the Spotify Web Playback SDK fails to start/play a track; the store captures the error and falls back to the YouTube player. If the free fallback is disabled or no audio element exists, the captured error is classified and rethrown as a player error.","triggerScenarios":"Calling the Spotify play path when the SDK cannot initialize: Premium authentication failure, device not registered as the active playback device, unsupported browser (no EME/DRM), or a track unavailable on Spotify.","commonSituations":"User without Spotify Premium; Spotify OAuth token expired or scopes missing (streaming/user-read-email); Chrome/Firefox DRM disabled; corporate network blocking Spotify CDN endpoints.","solutions":["Ensure Spotify Premium and re-authenticate with the streaming scopes","Enable DRM (Widevine/EME) in the browser and use a supported browser","Keep spotifyFreeFallback enabled (and an audio element present) so the YouTube fallback can take over","Check the Spotify device is active: open another Spotify session or re-select the device to register it"],"exampleFix":"// before\nthrow sdkErr ?? new Error(\"spotify sdk failed\");\n// after\nif (this.spotifyFreeFallback && this.audio) {\n  await this.playViaYoutubeFallback(track);\n} else {\n  throw classifyPlayerError(sdkErr ?? \"spotify sdk failed\", \"spotify\", track.id);\n}","handlingStrategy":"fallback","validationCode":"const canSpotify = Boolean(spotifyToken) && ('MediaSession' in navigator) && navigator.mediaDevices !== undefined;","typeGuard":"function hasSpotifySdk(w: Window): w is Window & { Spotify: { Player: new (o: unknown) => unknown } } { return \"Spotify\" in w && typeof (w as any).Spotify?.Player === \"function\"; }","tryCatchPattern":"try { await startSpotifySdk(track); return; } catch (e) { console.warn(\"[player] Spotify SDK failed, trying YouTube fallback:\", e); if (spotifyFreeFallback && audio) { await playViaYoutube(track); } else { throw classifyPlayerError(e, \"spotify\", track.id); } }","preventionTips":["Verify Premium status and OAuth streaming scopes before attempting SDK playback","Enable browser DRM (EME/Widevine) requirements in docs","Always keep the YouTube fallback path enabled for free users","Register/activate the Spotify device before transferring playback"],"tags":["spotify","sdk","playback","fallback"],"backgroundTag":"api-error-response","analyzedSha":"8600b91f4246848bac346874daa9e61c1fc5677a","analyzedAt":"2026-09-12T14:29:19.317Z","contentChangedAt":"2026-09-12T14:29:19.317Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}