Trouble with autoplaying audio via html in Quest 5.9 #1426
Replies: 5 comments 4 replies
-
This is correct. It's because the browser was updated, and it's the browser policy. The easiest solution (as you've found) is to add something before play begins to make the user interact. (I'm about to test out a second approach, but I'm 50/50 on whether or not it will work. UPDATE: It didn't work.) |
Beta Was this translation helpful? Give feedback.
-
Here's a different approach: This uses a dialog window to fake a prompt. When OK is clicked, it uses Tested in Firefox and in the desktop version of Quest 5.9 on Windows 10 . <!--Saved by Quest 5.9.9166.36226-->
<asl version="580">
<include ref="English.aslx" />
<include ref="Core.aslx" />
<game name="Prompt to Play Audio">
<gameid>1c2ee527-e8b7-4c7a-bab2-b6d807bac155</gameid>
<version>0.0 alpha</version>
<firstpublished>2025</firstpublished>
<feature_advancedscripts />
<inituserinterface type="script">
ShowFakePrompt
</inituserinterface>
</game>
<object name="room">
<inherit name="editor_room" />
<object name="player">
<inherit name="editor_object" />
<inherit name="editor_player" />
</object>
<exit alias="north" to="halllway">
<inherit name="northdirection" />
</exit>
</object>
<object name="halllway">
<inherit name="editor_room" />
<exit alias="south" to="room">
<inherit name="southdirection" />
</exit>
</object>
<function name="ShowFakePrompt">
JS.eval ("$('#msgboxCaption').html('This game includes audio.'); var msgboxOptions = { modal: true, autoOpen: false, title: 'Attention!', buttons: [{ text: 'OK', click: function () { ASLEvent ('PlayAmbientSound',''); $(this).dialog('close'); }}, ], closeOnEscape: false, }; $('#msgbox').dialog(msgboxOptions); $('#msgbox').dialog('open');")
</function>
<function name="PlayAmbientSound" parameters="unused"><![CDATA[
JS.eval ("$('audio').remove(); $('" + Chr(60) + "audio src=\"" + GetFileURL("ambient sound.ogg") + "\" autoplay loop/>').insertBefore($('#divOutput'));")
]]></function>
</asl> https://textadventures.co.uk/games/view/cve-ibbdkeek9zc_j2zhdq/prompt-to-play-audio |
Beta Was this translation helpful? Give feedback.
-
Excellent, thanks for your help! |
Beta Was this translation helpful? Give feedback.
-
One last time: As of Quest 5.9, the desktop player can handle MP3 in HTML audio elements. So, we no longer need OGG just for that. Here's the version that uses jQuery dialog as a prompt, only it uses MP3 rather than OGG -- and it has a command to play a second sound while the first is still playing. <!--Saved by Quest 5.9.9166.36226-->
<asl version="580">
<include ref="English.aslx" />
<include ref="Core.aslx" />
<game name="Prompt to Play Audio">
<gameid>1c2ee527-e8b7-4c7a-bab2-b6d807bac155</gameid>
<version>0.1 alpha</version>
<firstpublished>2025</firstpublished>
<feature_advancedscripts />
<inituserinterface type="script">
ShowFakePrompt
</inituserinterface>
<subtitle>v{game.version}</subtitle>
<author>KV (writing as Richard Bachman)</author>
<description><![CDATA[Testing game<br/>© 2025 QuestForumQuesters<br/>Written for Quest 5.9<br/>ASL 580<br/>8/FEB/2025]]></description>
<cover>wipq59.png</cover>
</game>
<command name="test">
<pattern>test</pattern>
<script>
msg("Playing announcement...")
play sound ("announcement.mp3", true, false)
msg ("Announcement done.")
</script>
</command>
<object name="room">
<inherit name="editor_room" />
<description>{command:TEST}</description>
<object name="player">
<inherit name="editor_object" />
<inherit name="editor_player" />
</object>
<exit alias="north" to="halllway">
<inherit name="northdirection" />
</exit>
</object>
<object name="halllway">
<inherit name="editor_room" />
<exit alias="south" to="room">
<inherit name="southdirection" />
</exit>
</object>
<function name="ShowFakePrompt">
JS.eval ("$('#msgboxCaption').html('This game includes audio.'); var msgboxOptions = { modal: true, autoOpen: false, title: 'Attention!', buttons: [{ text: 'OK', click: function () { ASLEvent ('PlayAmbientSound',''); $(this).dialog('close'); }}, ], closeOnEscape: false, }; $('#msgbox').dialog(msgboxOptions); $('#msgbox').dialog('open');")
</function>
<function name="PlayAmbientSound" parameters="unused"><![CDATA[
JS.eval ("$('audio').remove(); $('" + Chr(60) + "audio src=\"" + GetFileURL("ambient_sound.mp3") + "\" autoplay loop/>').insertBefore($('#divOutput'));")
]]></function>
</asl> https://textadventures.co.uk/games/view/cve-ibbdkeek9zc_j2zhdq/prompt-to-play-audio |
Beta Was this translation helpful? Give feedback.
-
On a game I've been working on for a couple of years, I used the standard autoplay audio element extensively:
src = GetFileURL("background music.ogg")
ID = "background-music"
msg ("")
It no longer functions as is in Quest 5.9. Does the new Chrome build block autoplay like the browser does? I was able to get it to work via javascript, but only with user interaction (pressing a button). That lines up with what I've read about Chrome's autoplay policy (only playing [or unmuting] audio with a user gesture). Otherwise, all the tricks I read about on stack overflow did nothing.
Anyone else having trouble with this? Any possible solutions?
Beta Was this translation helpful? Give feedback.
All reactions