bug: flet-audio on Android: starting one `Audio` permanently pauses any other playing `Audio`
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 35/100
調査の方向性
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.
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- Python
- スター
- 17.5k
- フォーク
- 740
- 平均マージ
- 1日 15時間
- マージ済み PR(30日)
- 65
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
flet-dev/flet のほかの issue
-
feature request
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
flet-dev/flet#6985 · コメント 3 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
bug: `use_state` with a callable initializer is inferred ambiguously by ty and mypy対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
flet build: common [tool.flet.deep_linking] is ignored on Android and iOS対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープンbug packaging platform: mobile
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
bug: Windows build fails silently in Flet 1.0.5 packaging stage and produces incomplete Python runtime (missing dependencies such as certifi)対応中かも @ndonkoHenri が 2 日前に担当しました。 オープンbug
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
flet-dev/flet#7029 · コメント 3 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
enhancement good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
elviskahoro/sdk-python-attio#144 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
RenyiELBO raises TypeError when model has no sample sites対応中かも @alibb007 が今日担当しました。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信