fix(audio): Spotify resumed nach Mute — RNSound's haengenden Focus loesen
Logs zeigten: react-native-sound requestet beim Sound.play() einen EIGENEN AudioFocus mit USAGE_MEDIA, released den aber bei Sound.stop()/ release() NICHT (bekanntes RN-sound-Bug). Spotify sieht den haengenden Media-Focus → bleibt pausiert. Workaround: Native-Methode kickReleaseMedia() macht einen request+abandon- Cycle mit USAGE_MEDIA, das System raeumt damit den Focus-Stack auf und Spotify bekommt sauberen GAIN-Event. stopPlayback ruft das jetzt nach Sound.release() wenn vorher ein RNSound aktiv war. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -41,6 +41,8 @@ const { AudioFocus, PcmStreamPlayer } = NativeModules as {
|
||||
requestDuck: () => Promise<boolean>;
|
||||
requestExclusive: () => Promise<boolean>;
|
||||
release: () => Promise<boolean>;
|
||||
kickReleaseMedia: () => Promise<boolean>;
|
||||
getMode?: () => Promise<number>;
|
||||
};
|
||||
PcmStreamPlayer?: {
|
||||
start: (sampleRate: number, channels: number, prerollSeconds: number) => Promise<boolean>;
|
||||
@@ -1196,6 +1198,10 @@ class AudioService {
|
||||
stopBackgroundAudio().catch(() => {});
|
||||
this.audioQueue = [];
|
||||
this.isPlaying = false;
|
||||
// Merken: war ein react-native-sound-Sound aktiv? Dann muessen wir nach
|
||||
// release() den Focus-Stack aufmischen (RNSound-Bug: stop+release laesst
|
||||
// den AudioFocusRequest haengen, Spotify resumed sonst nicht).
|
||||
const hadRnSound = !!(this.currentSound || this.resumeSound || this.preloadedSound);
|
||||
if (this.currentSound) {
|
||||
this.currentSound.stop();
|
||||
this.currentSound.release();
|
||||
@@ -1224,6 +1230,11 @@ class AudioService {
|
||||
// Audio-Focus sofort freigeben — User hat explizit abgebrochen
|
||||
this._cancelDeferredFocusRelease();
|
||||
AudioFocus?.release().catch(() => {});
|
||||
if (hadRnSound) {
|
||||
// RNSound's haengender USAGE_MEDIA-Focus aufloesen — sonst bleibt
|
||||
// Spotify pausiert obwohl unser Focus released ist.
|
||||
AudioFocus?.kickReleaseMedia?.().catch(() => {});
|
||||
}
|
||||
}
|
||||
|
||||
// --- Status & Callbacks ---
|
||||
|
||||
Reference in New Issue
Block a user