KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: How to prevent a buzzing sound while playing "snd" resources
PRODUCT: 4D | VERSION: 6.5 | PLATFORM: Mac & Win
Published On: June 15, 2001
Your current browser may not allow you to download the asset. We recommend Mozilla Firefox or Google Chrome.
Log In

Using the PLAY command to play "snd" resources asynchronously will work fine. However, if the user performs an interface task, like opening a window, in the custom menus environment while the "snd" resource is playing, the sound could turn into a buzzing sound. If you find that the "snd" plays as a buzzing sound while doing UI tasks, you can solve the problem by first reading in the sound resource from the sound file and writing it to a resource in the structure file. The following code demonstrates how to do so:


$FileName:=$1

PLAY("";0)` Stop any sound currently playing.

If (Test path name($FileName)#Is a document )
 ALERT("Could not open the "+$FileName+" sound file.")
Else
 $ResourceFileRef:=Open resource file($FileName)
 If (OK=1)
   GET RESOURCE("snd ";1555;$SoundResourceData;$ResourceFileRef)
   CLOSE RESOURCE FILE($ResourceFileRef)

   If (OK=1)
     SET RESOURCE("snd ";17000;$SoundResourceData)
     CLEAR VARIABLE($SoundResourceData)
     SET RESOURCE NAME("snd ";17000;$FileName)
     SET RESOURCE PROPERTIES("snd ";17000;Purgeable resource mask )
     PLAY($FileName;0)` Play the sound asynchronously.
   Else
      ALERT("Could not get the sound resource.")
   End if
   Else
     ALERT("Cound not open the resource file.")
 End if
End if