Skip to content

bug: Audio widget plays file only once, subsequent play() calls do nothing (Android) #5658

@ozoMain

Description

@ozoMain

Duplicate Check

Describe the bug

Audio can only be played once. On subsequent attempts to play the audio file, nothing happens — no playback starts and no errors are shown.

Code sample

Code
import flet as ft
import flet_audio_recorder as ftar
import flet_audio as fta

def main(page: ft.Page):
    page.horizontal_alignment = ft.CrossAxisAlignment.CENTER
    page.appbar = ft.AppBar(title=ft.Text("Audio Recorder"), center_title=True)

    path = "test-audio-file.wav"

    def handle_start_recording(e):
        print(f"StartRecording: {path}")
        audio_rec.start_recording(path)

    def handle_stop_recording(e):
        output_path = audio_rec.stop_recording()
        print(f"StopRecording: {output_path}")
        if page.web and output_path is not None:
            page.launch_url(output_path)
        page.update()

    def handle_state_change(e):
        print(f"State Changed: {e.data}")

    audio_rec = ftar.AudioRecorder(
        on_state_changed=handle_state_change,
    )

    audio_play = fta.Audio("non-existent", autoplay=False, volume=6)
    page.overlay.append(audio_play)

    def handle_start_play(e):
        audio_play.src = path
        page.add(ft.Text(f"play audio file: {audio_play.src}"))
        audio_play.update()
        audio_play.play()

    print(f"audio recorder: {audio_rec}")
    page.overlay.append(audio_rec)
    page.update()

    page.add(
        ft.ElevatedButton("Start Audio Recorder", on_click=handle_start_recording),
        ft.ElevatedButton("Stop Audio Recorder", on_click=handle_stop_recording),
        ft.ElevatedButton("Play", on_click=handle_start_play),
    )


ft.app(main)

To reproduce

Run the app using flet run --android.

Scan the QR code on the Android device.

Start recording with AudioRecorder.

Stop the recording to save the audio file.

Play the recorded file using Audio.

Try to play the same audio file again.

Playback does not start, no errors in logs.

Expected behavior

It should be possible to play the same audio file multiple times without issues.

Screenshots / Videos

Captures

[Upload media here]

Operating System

Linux

Operating system details

Linux Mint 22.1

Flet version

0.28.3

Regression

I'm not sure / I don't know

Suggestions

No response

Logs

Logs
flet run --android
/home/ozo/Documents/Projects/AudioControl/.venv/lib/python3.12/site-packages/websockets/legacy/__init__.py:6: DeprecationWarning: websockets.legacy is deprecated; see https://websockets.readthedocs.io/en/stable/howto/upgrade.html for upgrade instructions
  warnings.warn(  # deprecated in 14.0 - 2024-11-09
/home/ozo/Documents/Projects/AudioControl/.venv/lib/python3.12/site-packages/uvicorn/protocols/websockets/websockets_impl.py:17: DeprecationWarning: websockets.server.WebSocketServerProtocol is deprecated
  from websockets.server import WebSocketServerProtocol
App is running on: http://192.168.0.134:8551/src/main.py

█████████████████████████████████████████
█████████████████████████████████████████
████ ▄▄▄▄▄ ██   ▀ ▀▄▀ ▄▄▄▀█▄██ ▄▄▄▄▄ ████
████ █   █ █ ▀▄▄▀▄▀▄ █▄  ▀▀ ██ █   █ ████
████ █▄▄▄█ █  ▀ ▄▄▀ ▀█▄██▀█▀ █ █▄▄▄█ ████
████▄▄▄▄▄▄▄█ █▄█ ▀▄▀▄█ █ ▀ █▄█▄▄▄▄▄▄▄████
████ █   ▄▄███ █▄██▄ ▄▀ ██▄ ▄█  ▄  ██████
███████ ▀ ▄▀ ▄▄▀██▀███ █▀█▀▀ ▄▄█ ▀ ▄ ████
████ ▀ ▀▀█▄▀▄██  █▀ ▀█ █▄  ██▄▄▀█ ▀  ████
████▄ ██▀ ▄ ▄▀▀▄▄▀▄█▀██ ▄ ▄▄▄    █▀▄█████
████▄▄ ▀▀ ▄██▄▀▄▄███▄ █  ██ █▄▀ ▄▀▀█ ████
████▄  █▀ ▄▄█▀ █▀▀▀ █ ▀█ ▀▀█▄▀█  ▀ █▀████
████  ▄▀ █▄▀  ▄▄█▀  ▄█▀██▄ ██▄▀▄▀▄▀▄▀████
████ █▀▄▀█▄▀▄ █ █▄▄ ▄▄▀ ▄▀▄  ▀█▀▀▀█▄█████
████▄█▄▄█▄▄▄▀█▄▄██▀ ▄▄  ▀█▄█ ▄▄▄ ▄▀▀ ████
████ ▄▄▄▄▄ █▀▄ ██▀██ █▄█▀ █  █▄█ ▀  ▀████
████ █   █ █ ██▄▀   ▀█▄▄   █▄ ▄▄  ▀▀▄████
████ █▄▄▄█ █▄▀▀ ▀▀ █▀▀ ▀█▀▄▄▀█▄▄▀▄▄██████
████▄▄▄▄▄▄▄█▄█▄▄▄███▄▄▄▄██▄█▄▄█▄██▄▄█████
█████████████████████████████████████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀

Scan QR code above with Camera app.
/home/ozo/Documents/Projects/AudioControl/.venv/lib/python3.12/site-packages/websockets/legacy/server.py:1178: DeprecationWarning: remove second argument of ws_handler
  warnings.warn("remove second argument of ws_handler", DeprecationWarning)
audio recorder: audiorecorder {}
StartRecording: test-audio-file.wav
State Changed: recording
State Changed: stopped
StopRecording: test-audio-file.wav

Additional details

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions