Code: Select all
ini_Signal$ = "C:\Windows\Media\Alarm01.wav"
;- InitSound
Global IsSound = 0
#RingTone = 0
If Asc(ini_Signal$) And FileSize(ini_Signal$) > 0 And InitSound()
If LoadSound(#RingTone, ini_Signal$)
IsSound = SoundLength(#RingTone, #PB_Sound_Millisecond)
If IsSound > 3000
IsSound = 3000
EndIf
EndIf
EndIf
success = 1
If success And IsSound
PlaySound(#RingTone)
Delay(IsSound)
EndIf
The sound in the thread does not block the window.
Code: Select all
EnableExplicit
Define x, success
Define ini_Signal$ = "C:\Windows\Media\Alarm01.wav"
Global IsSound = 0
#RingTone = 0
If Asc(ini_Signal$) And FileSize(ini_Signal$) > 0 And InitSound()
If LoadSound(#RingTone, ini_Signal$)
IsSound = SoundLength(#RingTone, #PB_Sound_Millisecond)
EndIf
EndIf
Procedure Sound(*Value)
If PeekI(*Value) = 1 And IsSound
PlaySound(#RingTone)
Delay(IsSound)
EndIf
EndProcedure
If OpenWindow(0, 0, 0, 420, 100, "The sound in the thread does not block the window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ButtonGadget(1, 10, 10, 99, 30, "Sound")
ButtonGadget(2, 10, 50, 242, 30, "click when a melody is playing")
Repeat
Select WaitWindowEvent()
Case #PB_Event_Gadget
Select EventGadget()
Case 2
x + 1
SetGadgetText(2, Str(x))
Case 1
success = 1 ; some operation was successful, signaling with a sound
CreateThread(@Sound(), @success)
EndSelect
Case #PB_Event_CloseWindow
CloseWindow(0)
End
EndSelect
ForEver
EndIf