Page 1 of 1

A question on a small working code.

Posted: Mon Apr 08, 2024 1:59 pm
by jphoarau
I have a question. Can anyone explain to me why I have to click in the main browser window to hear the sound?
Below is the code which apparently works very well, apart from this small detail. What did I forget? Thanks in advance.

Code: Select all

Global Start = ElapsedMilliseconds()

If InitSound()
  Debug "initsound MainForm OK"
EndIf

#Sound1 = 1

Procedure TimerEvent()
  Debug "Elapsed time in ms: " + Str(ElapsedMilliseconds()-Start)
  PlaySound(#Sound1)
EndProcedure

Procedure Loading(Type, Filename$)
  OpenWindow(0, 0, 0, 100, 100, "Timer", #PB_Window_Invisible)
  ;SetActiveWindow(0)
  AddWindowTimer(0, 0, 1000)
EndProcedure

Procedure LoadingError(Type, Filename$)
  Debug Filename$ + ": loading error"
EndProcedure

BindEvent(#PB_Event_Loading, @Loading())
BindEvent(#PB_Event_LoadingError, @LoadingError())
BindEvent(#PB_Event_Timer, @TimerEvent())

LoadSound(#Sound1, "./res/Sounds/Recording_10.mp3")

Re: A question on a small working code.

Posted: Mon Apr 08, 2024 2:31 pm
by Peter
jphoarau wrote: Mon Apr 08, 2024 1:59 pmCan anyone explain to me why I have to click in the main browser window to hear the sound?
Developer-Console wrote:The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on the page.

Re: A question on a small working code.

Posted: Mon Apr 08, 2024 2:37 pm
by Quin
The ability for sounds to play has to be triggered by a user action on the page. This is incredibly annoying, but it's a limitation of the web everywhere. Part of me gets why, but it's still annoying when you're making an application that uses a lot of sounds.

Re: A question on a small working code.

Posted: Mon Apr 08, 2024 3:08 pm
by jphoarau
Quin wrote: Mon Apr 08, 2024 2:37 pm The ability for sounds to play has to be triggered by a user action on the page. This is incredibly annoying, but it's a limitation of the web everywhere. Part of me gets why, but it's still annoying when you're making an application that uses a lot of sounds.
All right. I don't understand why, but it is not an error from me. I am reassured.:) Thank you.

Re: A question on a small working code.

Posted: Mon Apr 08, 2024 3:30 pm
by Quin
jphoarau wrote: Mon Apr 08, 2024 3:08 pm All right. I don't understand why, but it is not an error from me. I am reassured.:) Thank you.
You're most certainly not the only one that doesn't understand this. We can run any javascript we want on page load... unless it plays sounds? :?

Re: A question on a small working code.

Posted: Tue Apr 09, 2024 10:39 am
by jphoarau
Quin wrote: Mon Apr 08, 2024 3:30 pm You're most certainly not the only one that doesn't understand this. We can run any javascript we want on page load... unless it plays sounds? :?
Yes. Perhaps, one day, I will understand? But for now, I don't even ask myself the question. :D