St.audio with autoplay=True only plays once

I have an app for the 30-seconds game: https://30-seconds.streamlit.app/ where players get 30 seconds to describe the words in view. After the time is up a sound should play.
This works the first round, but in following rounds the audio widget is displayed but the autoplay is no longer triggered. How can I make the app play the sound each round?

github: 30_seconds/app.py at main · DatalabHvA/30_seconds · GitHub

Hey @p.c.bons,

Thanks for sharing this question! I’m not able to get the app to play the sound the first time – did you remove the part of the app that played the sound?

Hi @Caroline,

sorry you’re right. I removed it because it wasn’t working properly but now I put it back so hopefully you can see the problem.

thanks!

Hey @p.c.bons,

Sorry for the delayed follow up! I’ve been trying to debug this issue and found out that browsers won’t autoplay audio files if the current user hasn’t interacted with the page by clicking somewhere during the initial loading of the page – this means that autoplay won’t work on st.audio widgets that are added after the initial loading of the app.

I’ve asked the team to update our doc for st.audio to make this much clearer, since it’s obviously a limitation that can be quite frustrating if you weren’t aware until after you tried implementing it. Apologies for the confusion!

1 Like

Hi @Caroline ,

Thanks a lot for your effort and investigation. Do you know of a good alternative to play a sound multiple times in a web app?

Regards,
Pieter