Native Android client for Spotify, built with Jetpack Compose
Kotlin ad-freeadblockandroidjetpack-composekotlinlyricsmusic-playermusic-videomyspotispotifyspotify-adblockerspotify-clientspotify-connectspotui
An ad stays unheard after a song is picked: the page raised its own volume after the mute (a new song, its fade-in, a Spotify Connect volume) and the ad was heard until the next mute two seconds later; every page media element is now held silent from its first play while an ad is muted or the page hushed (ad_pick heard 2 times in 2 before, ad_taps, ad_previous and ad_pick 16/16 after)
kota-zo64765768200c
diff --git a/base/api-spotify/src/main/resources/bridge/player-bridge.js b/base/api-spotify/src/main/resources/bridge/player-bridge.jsindex dbee9fb1..e3c256ce 100644--- a/base/api-spotify/src/main/resources/bridge/player-bridge.js+++ b/base/api-spotify/src/main/resources/bridge/player-bridge.js@@ -229,6 +229,17 @@// Not heard, yet not "muted audio" to Chromium (see 'media.mute').const SILENT = 0.001;+ // Holds an element unheard while an ad is muted or the page hushed: the page sets its own volume+ // again after a mute (a new song, its fade-in, a Spotify Connect volume), and a one-off set left+ // the ad heard until the next mute two seconds later. The host's document-start hook puts the+ // same guard on every element from its first play (window.__mspSilence); this one is the fallback.+ const silence = window.__mspSilence || (el => {+ if (el.__mspGuard) return;+ el.__mspGuard = () => { if ((window.__mspMuted || window.__mspHushed) && !el.muted && el.volume > SILENT) el.volume = SILENT; };+ el.addEventListener('volumechange', el.__mspGuard);+ el.addEventListener('playing', el.__mspGuard);+ });+// A fade is a list of setTimeout steps: a second fade, a plain volume set or a mute must// cancel the pending ones, or they would override it seconds later (the up-ramp of a// crossfade undone by the tail of its own down-ramp, a restored volume pulled down again).@@ -463,6 +474,7 @@// The end of an ad's mute leaves a hushed page unheard ('media.hush'): seen, the page heard// over the local player it mirrors after an ad, on an element the hush had not reached yet.for (const el of els) {+ silence(el);el.muted = false;el.volume = a.on || window.__mspHushed ? SILENT : (player && el === player._player ? ownLevel(player) : 1);}@@ -478,11 +490,7 @@const player = await localPlayer().catch(() => null);const els = new Set([...(window.__mspMedia || []), ...document.querySelectorAll('audio, video'), ...await playerMedia()]);for (const el of els) {- if (!el.__mspHush) {- el.__mspHush = () => { if (window.__mspHushed && !window.__mspMuted && el.volume > SILENT) el.volume = SILENT; };- el.addEventListener('volumechange', el.__mspHush);- el.addEventListener('playing', el.__mspHush);- }+ silence(el);if (a.on) { cancelFade(); el.muted = false; el.volume = SILENT; }else if (!window.__mspMuted) el.volume = player && el === player._player ? ownLevel(player) : 1;}diff --git a/base/host-android/src/main/kotlin/app/myspoti/host/android/ControlRelay.kt b/base/host-android/src/main/kotlin/app/myspoti/host/android/ControlRelay.ktindex 95143c7b..da6031c5 100644--- a/base/host-android/src/main/kotlin/app/myspoti/host/android/ControlRelay.kt+++ b/base/host-android/src/main/kotlin/app/myspoti/host/android/ControlRelay.kt@@ -825,9 +825,19 @@ internal class ControlRelay(private val view: WebView, private val fingerprint:// Silent is a tiny volume, never muted: Chromium pauses muted media of a hidden page.const media = new Set();window.__mspMedia = media;+ // Held silent from its first play while the flags stand: the page raises its own+ // volume after a mute (a new song, its fade-in, a Connect volume), which left an ad heard.+ const silence = el => {+ if (el.__mspGuard) return;+ el.__mspGuard = () => { if ((window.__mspMuted || window.__mspHushed) && !el.muted && el.volume > 0.001) el.volume = 0.001; };+ el.addEventListener('volumechange', el.__mspGuard);+ el.addEventListener('playing', el.__mspGuard);+ };+ window.__mspSilence = silence;const play = HTMLMediaElement.prototype.play;HTMLMediaElement.prototype.play = function () {media.add(this);+ silence(this);if (window.__mspMuted || window.__mspHushed) { this.muted = false; this.volume = 0.001; }return play.apply(this, arguments);};