You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Platforms you faced the error (IOS or Android or both?)
Android (not tested on IOS)
Expected behavior
If spotify is currently playing, my expectation is that AudioFocus.focusAndHushOthers should lower spotify's volume while playing the sounds audio.
Actual behavior
AudioFocus.focusAndHushOther and AudioFocus.focusAndKeepOthers both stop spotify playback without resuming it post playback.
I have tried this with headless playback and with the shade UI.
Tested environment (Emulator? Real Device?)
Real Device (Galaxy 8+), can't imagine it'd be any different on the emulator.
Steps to reproduce the behavior
static void playSound(){
var track = Track.fromAsset('assets/sounds/english/finish.mp3');
var player = SoundPlayer.noUI();
player.onStopped = ({wasUser}) => player.release();
player.audioFocus(AudioFocus.focusAndHushOthers);
player.play(track);
}
The short term fix is you simply need to release the audio focus in the player.onStopped method by setting the audioFocus to abandonFocus. player.audioFocus(AudioFocus.abandonFocus)
That being said I'm currently working on some changes which will allow you to automate this process. They should be available in a release soon. Ill update this thread when it's done.
So this is actually a bug. We're currently working through some API design issues regarding focus management as a whole but the coming changes will fix your issue. Once we get past this we'll do a release, most likely this coming Tuesday.
From that point all the code you'll need to do what you are doing is var track = Track.fromAsset('assets/sample.mp3'); var player = SoundPlayer.noUI(); player.onStopped = ({wasUser}) => player.release(); player.play(track);
Sorry for the incorrect fix I gave you and thanks for the detailed reports.
These changes including the fix to this bug are now available in version 1.0.0-beta13.
The release focuses heavily on focus management, most notably implementing the autoFocus property (true by default) on SoundPlayer and SoundPlayerUI which automatically sets audio focus to hushOthersWithResume and abandons focus after the audio completes. Furthermore focus can still be managed explicitly and the focus options have been renamed to be more clear. The options are now:
stopOthersNoResume,
stopOthersWithResume,
hushOthersWithResume.
WithResume refers to whether other audio streams will return to their initial volume/state after abandon focus is called.
Activity
relf108 commentedon Sep 1, 2020
The short term fix is you simply need to release the audio focus in the player.onStopped method by setting the audioFocus to abandonFocus.
player.audioFocus(AudioFocus.abandonFocus)That being said I'm currently working on some changes which will allow you to automate this process. They should be available in a release soon. Ill update this thread when it's done.
Ro-El commentedon Sep 1, 2020
Is something like this what you are referring to?
Because this also does not seem to work:
static void playSound(){
var track = Track.fromAsset('assets/sounds/english/Finish.mp3');
var player = SoundPlayer.noUI();
// player.onStopped = ({wasUser}) => player.release();
player.onStopped = ({wasUser}){
player.audioFocus(AudioFocus.abandonFocus);
player.release();
};
player.audioFocus(AudioFocus.focusAndHushOthers);
player.play(track);
}
Thanks again for all the help!
relf108 commentedon Sep 2, 2020
So this is actually a bug. We're currently working through some API design issues regarding focus management as a whole but the coming changes will fix your issue. Once we get past this we'll do a release, most likely this coming Tuesday.
From that point all the code you'll need to do what you are doing is
var track = Track.fromAsset('assets/sample.mp3'); var player = SoundPlayer.noUI(); player.onStopped = ({wasUser}) => player.release(); player.play(track);Sorry for the incorrect fix I gave you and thanks for the detailed reports.
relf108 commentedon Sep 7, 2020
These changes including the fix to this bug are now available in version 1.0.0-beta13.
The release focuses heavily on focus management, most notably implementing the autoFocus property (true by default) on SoundPlayer and SoundPlayerUI which automatically sets audio focus to hushOthersWithResume and abandons focus after the audio completes. Furthermore focus can still be managed explicitly and the focus options have been renamed to be more clear. The options are now:
stopOthersNoResume,
stopOthersWithResume,
hushOthersWithResume.
WithResume refers to whether other audio streams will return to their initial volume/state after abandon focus is called.