bug: flet-audio on Android: starting one `Audio` permanently pauses any other playing `Audio`
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
Direzione di ricerca
The cause sits in the Dart side of flet-audio: AudioService in sdk/python/packages/flet-audio/src/flutter/flet_audio/lib/src/audio.dart creates one AudioPlayer per Audio and never calls setAudioContext. Reproducing needs an Android build, since the focus loss happens in audioplayers' Android code. Done would mean exposing a focus setting on the Python Audio control that is applied to its player, with the two-player case no longer pausing the music.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Duplicate Check
- I have searched the opened issues and there are no duplicates
Describe the bug
On Android, playing an Audio pauses every other Audio that is already playing, and the paused one never resumes. For example, looping background music stops as soon as a short sound effect plays. On desktop both play together as expected.
The cause appears to be Android audio focus in audioplayers:
AudioServicecreates oneAudioPlayerperAudioand never callssetAudioContext(audio.dart), so every player uses audioplayers' default Android context withaudioFocus = AUDIOFOCUS_GAIN(AudioContextAndroid.kt).- Each player requests focus with its own
AudioFocusRequestwhen it starts (FocusManager.kt). Android grants focus per request, not per app, so the player that was already playing receivesAUDIOFOCUS_LOSS. - On a permanent loss,
WrappedPlayercallspause()with the comment "Audio focus won't be recovered" (WrappedPlayer.kt).
There is currently no way to change this from Python, because Audio exposes no audio context or focus setting.
Code sample
Code
import flet as ft
import flet_audio as fta
def main(page: ft.Page):
status = ft.Text("Music: -")
def on_music_state(e: fta.AudioStateChangeEvent):
status.value = f"Music: {e.state.name}"
status.update()
fta.Audio(
src="https://luan.xyz/files/audio/ambient_c_motion.mp3",
autoplay=True,
release_mode=fta.ReleaseMode.LOOP,
on_state_change=on_music_state,
)
async def play_effect(e):
await fta.Audio(src="https://luan.xyz/files/audio/coins.wav").play()
page.add(status, ft.Button("Play effect", on_click=play_effect))
ft.run(main)
To reproduce
- Build the sample with
flet build apk(withflet-audioin the dependencies) and install it on an Android device. - The music starts looping and the status shows
Music: PLAYING. - Tap "Play effect".
- The coin sound plays, the music stops, and the status shows
Music: PAUSED. The music does not resume after the effect ends.
Running the same code on desktop keeps the music playing under the effect.
Expected behavior
The effect plays on top of the music, as it does on desktop, or at least Flet offers a way to opt into that behaviour on Android.
Screenshots / Videos
Captures
[Upload media here]
Operating System
Linux
Operating system details
Android 16
Flet version
1.0.5 (flet-audio 1.0.5)
Regression
I'm not sure / I don't know
Suggestions
Expose the audioplayers audio focus on Audio, for example a property mapped to AudioContextConfigFocus (gain, duckOthers, mixWithOthers) and applied with player.setAudioContext(...). Background music could then keep gain, so it still pauses for phone calls and other music apps, while sound effects use mixWithOthers (AndroidAudioFocus.none) and play over it without taking focus.
A global option backed by AudioPlayer.global.setAudioContext(...) would also work around the bug, but it applies to every player, including the music.
Logs
Logs
[Paste your logs here]
Additional details
The same mechanism means narration or any second Audio stops the music, and overlapping effects cut each other off. When the interrupted Audio is an intro that hands over to a loop on COMPLETED, the loop never starts because the intro never completes.
- Lingua principale
- Python
- Stelle
- 17.5k
- Fork
- 740
- Merge medio
- 1g 15h
- PR unite (30g)
- 73
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di flet-dev/flet
-
feature: python 3.15 supportApertafeature request
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
flet-dev/flet#6985 · 3 commenti · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
bug: `use_state` with a callable initializer is inferred ambiguously by ty and mypyForse già presa Una pull request collegata a questa issue è aperta o già unita. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
flet build: common [tool.flet.deep_linking] is ignored on Android and iOSForse già presa Una pull request collegata a questa issue è aperta o già unita. Apertabug packaging platform: mobile
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
bug: Windows build fails silently in Flet 1.0.5 packaging stage and produces incomplete Python runtime (missing dependencies such as certifi)Forse già presa @ndonkoHenri l’ha presa 2 giorni fa. Apertabug
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
flet-dev/flet#7029 · 3 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di flet-dev/flet
Issue simili
-
New InternshipApertanew_internship
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
get_graph warns that the oneway column is missing when no way has a oneway tagForse già presa @HTenkanen l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
cython/cython#8110 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
fix: security 🔐 style: article/section 📝 system: data-mgmt 🗃️ system: security 🔐 system: software 💻
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
uabrc/uabrc.github.io#1267 ·
-
Link Checker ReportApertaBot Type: Bug Type: Documentation
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
I maintainer di solito rispondono entro 1 giorno