InitSound()
Procedure Loading(Type, Filename$, ObjectId)
Debug Filename$ + " loaded (id = " + ObjectId + ")"
PlaySound(0) ; play the sound
EndProcedure
Procedure LoadingError(Type, Filename$)
Debug Filename$ + ": loading error"
EndProcedure
; Register the loading event before calling any resource load command
BindEvent(#PB_Event_Loading, @Loading())
BindEvent(#PB_Event_LoadingError, @LoadingError())
; This works and plays fine
If LoadSound(0, "raf-self-control.mp3") ; Be sure this sound is available (the source file should be saved in the SpiderBasic/Examples drawer)
; This doesn't seem to adjust the volume
;PlaySound(0,#PB_Sound_Loop,50)
; This also doesn't seem to do anything
SoundVolume(0, 0)
EndIf
That said it would be better if it could work before the sound start or you can have a small time where it play with the wrong volume. I will investigate this.
Caronte3D wrote: Thu Dec 05, 2024 7:27 am
You must wait to the sound file to be loaded.
If you put the: SoundVolume(0, 0) after PlaySound(0) (inside Loading procedure), it works as expected.
Ah? Like this? I couldn't get it to work unless I removed the PlaySound(). I tried with PlaySound(0) etc. (Windows 11 if it matters)
; This example plays nothing, until you comment out PlaySound()
If LoadSound(0, "raf-self-control.mp3") ; Be sure this sound is available (the source file should be saved in the SpiderBasic/Examples drawer)
; Adding this back in results in no sound at all
PlaySound(0,#PB_Sound_Loop,20)
; This also doesn't seem to do anything by itself.
; In combination with PlaySound(), there is no audio even at 100 volume.
; Without PlaySound(), it does not set the volume.
SoundVolume(0, 20)
EndIf
If any workarounds are available I would like to try them out.
That said it would be better if it could work before the sound start or you can have a small time where it play with the wrong volume. I will investigate this.
InitSound()
Procedure Loading(Type, Filename$, ObjectId)
Debug Filename$ + " loaded (id = " + ObjectId + ")"
PlaySound(0) ; play the sound
EndProcedure
Procedure LoadingError(Type, Filename$)
Debug Filename$ + ": loading error"
EndProcedure
Procedure WaveVolume()
Static volume=0, incre=0
If volume=100 : incre=-1 : EndIf
If volume=0 : incre=1 : EndIf
volume+incre
SoundVolume(0, volume)
EndProcedure
; Register the loading event before calling any resource load command
BindEvent(#PB_Event_Loading, @Loading())
BindEvent(#PB_Event_LoadingError, @LoadingError())
; This works and plays fine
If LoadSound(0, "./raf-self-control.mp3") ; Be sure this sound is available (the source file should be saved in the SpiderBasic/Examples drawer)
AddTimer(0, 40) ; First timer every 100 seconds
BindEvent(#PB_Event_Timer, @WaveVolume())
EndIf