Page 1 of 1

How to play a background-sound (SND_ASYNC) ?

Posted: Mon Sep 09, 2019 5:01 pm
by ukoenig
Hello,

I want to play a background-sound a defined time
without blocking any possible actions using < SND_ASYNC >

That doesn't work because
the function returns immediately after beginning the sound

FOR I := 1 TO 3 // play sound 3 times
SndPlaySound( "Test.wav", 1 ) // 0 works but is blocking all actions
NEXT

SND_SYNC The sound is played synchronously and the function does not return until the sound ends.
SND_ASYNC The sound is played asynchronously and the function returns immediately after beginning the sound.
To terminate an asynchronously-played sound, call sndPlaySound with cSndName set to 0.
SND_NODEFAULT If the sound can't be found, the function returns silently without playing the default sound.
SND_MEMORY The parameter specified by cSndName to an in-memory image of a waveform sound.
SND_LOOP The sound will continue to play repeatedly until sndPlaySound is called again with the cSndName parameter set to 0.
You must also specify the SND_ASYNC flag to loop sounds.
SND_NOSTOP If a sound is currently playing, the function will immediately return FALSE without playing the requested sound.

#define SND_SYNC 0
#define SND_ASYNC 1
#define SND_NODEFAULT 2
#define SND_MEMORY 4
#define SND_LOOP 8
#define SND_NOSTOP 16

is there any solution
regards
Uwe :?:

How to play a background-sound (SND_ASYNC) ?

Posted: Mon Sep 09, 2019 9:03 pm
by Enrico Maria Giordano
Try

Code: Select all

SND_ASYNC + SND_LOOP
EMG

Re: How to play a background-sound (SND_ASYNC) ?

Posted: Tue Sep 10, 2019 12:58 pm
by ukoenig
Enrico,

I found a working solution
it works embedded inside the timer-function

A defined var < nSndtime1 > with 0 on init
The timer-function returns a valid time to play the sound
Now nSndtime1 starts with counter 1 to activate the sound
next the sound plays x times until reaching the max-value
and nSndtime1 is set to 0 again until new activated
( I have to test 3 different times at once :roll: )

It seems to be a bit complicated but works.

Code: Select all

// called from TIMER
FUNCTION GETDATA()

IF aVal[34] = .T. .and. nSndtime1 = 0 // 1. time is valid
     // 1. date with time and date-check 
     IF aVal[31] = 1 .and. aVal[29] = cTime .and. aVal[30] = dDate   
          nSndtime1 := 1 // sound aktivated from inside the valid time / date
...
...
ENDIF

IF nSndtime1 > 0            // sound aktivated 
    SndPlaySound( c_Pfad1 + ALLTRIM(aVal[33]), 1 ) // SND_ASYNC
    nSndtime1++             // sound repeat
    IF nSndtime1 > aVal[53] // max played
        nSndtime1 := 0  // reset
    ENDIF
ENDIF
 
regards
Uwe :D