Changeset View
Changeset View
Standalone View
Standalone View
extension/content-script.js
Show First 20 Lines • Show All 150 Lines • ▼ Show 20 Line(s) | |||||
151 | 151 | | |||
152 | var activePlayer; | 152 | var activePlayer; | ||
153 | // When a player has no duration yet, we'll wait for it becoming known | 153 | // When a player has no duration yet, we'll wait for it becoming known | ||
154 | // to determine whether to ignore it (short sound) or make it active | 154 | // to determine whether to ignore it (short sound) or make it active | ||
155 | var pendingActivePlayer; | 155 | var pendingActivePlayer; | ||
156 | var playerMetadata = {}; | 156 | var playerMetadata = {}; | ||
157 | var playerCallbacks = []; | 157 | var playerCallbacks = []; | ||
158 | 158 | | |||
159 | // Playback state communicated via media sessions api | ||||
160 | var playerPlaybackState = ""; | ||||
161 | | ||||
159 | var players = []; | 162 | var players = []; | ||
160 | 163 | | |||
161 | var pendingSeekingUpdate = 0; | 164 | var pendingSeekingUpdate = 0; | ||
162 | 165 | | |||
163 | addCallback("mpris", "play", function () { | 166 | addCallback("mpris", "play", function () { | ||
164 | playerPlay(); | 167 | playerPlay(); | ||
165 | }); | 168 | }); | ||
166 | 169 | | |||
▲ Show 20 Lines • Show All 193 Lines • ▼ Show 20 Line(s) | 345 | function registerPlayer(player) { | |||
360 | // what about "stalled" event? | 363 | // what about "stalled" event? | ||
361 | player.addEventListener("waiting", function () { | 364 | player.addEventListener("waiting", function () { | ||
362 | sendPlayerInfo(player, "waiting"); | 365 | sendPlayerInfo(player, "waiting"); | ||
363 | }); | 366 | }); | ||
364 | 367 | | |||
365 | // playlist is now empty or being reloaded, stop player | 368 | // playlist is now empty or being reloaded, stop player | ||
366 | // e.g. when using Ajax page navigation and the user nagivated away | 369 | // e.g. when using Ajax page navigation and the user nagivated away | ||
367 | player.addEventListener("emptied", function () { | 370 | player.addEventListener("emptied", function () { | ||
371 | // When the player is emptied but the website tells us it's just "paused" | ||||
372 | // keep it around (Bug 402324: Soundcloud does this) | ||||
373 | if (player === activePlayer && playerPlaybackState === "paused") { | ||||
fvogt: Doesn't `player.paused` work here? | |||||
No. This case here is so when you empty the player, e.g. use ajax page nav to navigate away, we stop controlling the player. It is always paused when emptied, so this would just noop. broulik: No. This case here is so when you empty the player, e.g. use ajax page nav to navigate away, we… | |||||
Ok, so this is even more of a hack than I thought. Can you add a && player == activePlayer check there? fvogt: Ok, so this is even more of a hack than I thought. Can you add a `&& player == activePlayer`… | |||||
374 | return; | ||||
375 | } | ||||
376 | | ||||
368 | // could have its own signal but for compat it's easier just to pretend to have stopped | 377 | // could have its own signal but for compat it's easier just to pretend to have stopped | ||
369 | sendPlayerInfo(player, "stopped"); | 378 | sendPlayerInfo(player, "stopped"); | ||
370 | }); | 379 | }); | ||
371 | 380 | | |||
372 | // opposite of "waiting", we finished buffering enough | 381 | // opposite of "waiting", we finished buffering enough | ||
373 | // only if we are playing, though, should we set playback state back to playing | 382 | // only if we are playing, though, should we set playback state back to playing | ||
374 | player.addEventListener("canplay", function () { | 383 | player.addEventListener("canplay", function () { | ||
375 | if (!player.paused) { | 384 | if (!player.paused) { | ||
▲ Show 20 Lines • Show All 317 Lines • ▼ Show 20 Line(s) | 701 | if (action === "metadata") { | |||
693 | // FIXME filter metadata, this stuff comes from a hostile environment after all | 702 | // FIXME filter metadata, this stuff comes from a hostile environment after all | ||
694 | 703 | | |||
695 | playerMetadata = json.payload; | 704 | playerMetadata = json.payload; | ||
696 | 705 | | |||
697 | sendMessage("mpris", "metadata", json.payload); | 706 | sendMessage("mpris", "metadata", json.payload); | ||
698 | } else if (action === "playbackState") { | 707 | } else if (action === "playbackState") { | ||
699 | var playbackState = json.payload; | 708 | var playbackState = json.payload; | ||
700 | 709 | | |||
710 | playerPlaybackState = playbackState; | ||||
701 | if (activePlayer) { | 711 | if (activePlayer) { | ||
702 | if (playbackState === "playing") { | 712 | if (playbackState === "playing") { | ||
703 | playerPlaying(activePlayer); | 713 | playerPlaying(activePlayer); | ||
704 | } else if (playbackState === "paused") { | 714 | } else if (playbackState === "paused") { | ||
705 | playerPaused(activePlayer); | 715 | playerPaused(activePlayer); | ||
706 | } | 716 | } | ||
707 | } | 717 | } | ||
708 | 718 | | |||
709 | } else if (action === "callbacks") { | 719 | } else if (action === "callbacks") { | ||
710 | playerCallbacks = json.payload; | 720 | playerCallbacks = json.payload; | ||
711 | sendMessage("mpris", "callbacks", json.payload); | 721 | sendMessage("mpris", "callbacks", json.payload); | ||
712 | } | 722 | } | ||
713 | }); | 723 | }); | ||
714 | } | 724 | } | ||
715 | } | 725 | } |
Doesn't player.paused work here?