bug: flet-audio on Android: starting one `Audio` permanently pauses any other playing `Audio`
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Python
- Star
- 17.5k
- Fork
- 740
- Merge trung bình
- 1 ngày 8 giờ
- Pull request đã merge (30 ngày)
- 72
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của flet-dev/flet
-
feature: python 3.15 supportĐang mởfeature request
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
flet-dev/flet#6985 · 3 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Web: `TextField.focus()` after `on_submit` discards keys typed while the focus request is in flightĐang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Web: TextField values set through the DOM (autofill-like) are lost; on_submit carries an empty valueĐang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
Maintainer thường phản hồi trong vòng 1 ngày
-
feature request
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của flet-dev/flet
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
pylint-dev/pylint#11791 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Rasterio granule reads never retry, so one 503 (Service Unavailable) fails the whole requestCó thể đã có người làm @chuckwondo đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
developmentseed/titiler-cmr#305 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
community enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
Maintainer thường phản hồi trong vòng 1 ngày