-
QuestionI can't play the same sound file repeatedly (using buttons) on Android. This problem doesn't exist on Windows. I don't know how I should write the code or make any settings? Code sampleimport flet as ft
async 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" # a recording file
url_1="MetroSVT.mp3"
async def handle_start_recording(e):
await audio_rec.start_recording_async(path)
async def handle_stop_recording(e):
output_path = await audio_rec.stop_recording_async()
if page.web and output_path is not None:
await page.launch_url_async(output_path)
audio_rec = ft.AudioRecorder(
audio_encoder=ft.AudioEncoder.WAV,
)
page.overlay.append(audio_rec)
await page.update_async()
audio1 = ft.Audio(
src=url_1,
autoplay=False,
volume=6,
balance=0,
)
page.overlay.append(audio1)
def handle_start_play(e):
audio1.src=path
audio1.update()
audio1.play()
await page.add_async(
ft.ElevatedButton("Start Audio Recorder", on_click=handle_start_recording),
ft.ElevatedButton("Stop Audio Recorder", on_click=handle_stop_recording),
ft.ElevatedButton("Play1", on_click=lambda _: audio1.play()),
ft.ElevatedButton("Play2", on_click=handle_start_play),
)
ft.app(target=main) Error messageNo response ------------------------------------------------------
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
Can you try adding page.on_error = lambda e: print(e.data) |
Beta Was this translation helpful? Give feedback.
-
After trying it, I found a solution for your reference. Just set "release_mode=ft.audio.ReleaseMode.STOP". At this time, the same audio file can be played repeatedly on the Android system, which is great. The program code is as follows: import flet as ft
ft.app(target=main) |
Beta Was this translation helpful? Give feedback.
-
@jkloip Thanks for your response. Your solution works, but I have another problem. "ReleaseMode.STOP" stops audio from another application. I need to play the sound from my app and keep the sound from the other app (ex: YouTube Music). Could you help me? |
Beta Was this translation helpful? Give feedback.
After trying it, I found a solution for your reference. Just set "release_mode=ft.audio.ReleaseMode.STOP". At this time, the same audio file can be played repeatedly on the Android system, which is great. The program code is as follows:
import flet as ft
async def main(page: ft.Page):
page.horizontal_alignment = ft.CrossAxisAlignment.CENTER
page.appbar = ft.AppBar(title=ft.Text("Audio Recorder"), center_title=True)
page.on_error = lambda e: print(e.data)