Hi!
I’m using Xojo 2017r.3 on Apple
Here is my code:
dim f as FolderItem
dim s as sound
f=GetFolderItem("/System/Library/Components/CoreAudio.component/Contents/SharedSupport/SystemSounds/telephony/dtmf-0.caf", FolderItem.PathTypeShell)
if f<>nil and f.Exists then
s=f.OpenAsSound
s.play
while s.IsPlaying
wend
s.play
end if
Why the sound play only once?
If i put on app.open the sound and then on button.action i just play and hit the button n times, it works!
What i’m doing wrong?
Your code should just play the sound twice then never play again if the sound was long it would lock up your entire application until the sound ended because of the loop you have after the .Play (unless you are doing this in a thread). Use Sound.PlayLooping if you want to repeatedly play a sound, then call Sound.Stop on a button to stop it.
dim f as FolderItem
dim s as sound
f=GetFolderItem("/System/Library/Components/CoreAudio.component/Contents/SharedSupport/SystemSounds/telephony/dtmf-0.caf", FolderItem.PathTypeShell)
if f<>nil and f.Exists then
s=f.OpenAsSound
s.playlooping
end if
You need to make sure that s is a property of the window or use a similar way of keeping that variable from going out of scope to keep the reference to the sound so you can stop it later with s.stop.
What do you actually want to do? Do you want to be able to play the sound n number of times?
Hi.
I want to dial a telefone number, like
12345678
this format works. it plays 12345678
but if i need to dial
112345588
it plays only 123458
i really can’t understand!
There’s probably half a dozen ways of doing what you want but here’s a little demo using CallLater
https://www.dropbox.com/s/ovibuw1nxnh7xc3/TestDTMF.xojo_binary_project?dl=1
Thank you for your example!
But i really would like to understand why my code does not work.
Why s.play and then s.play again, does not work when the sound file is the same?
Alex
No problem
Its either a bug or a feature/limitation on macos as it plays twice on windows 10.
To play it again under macos you need to either call s=f.openassound again or call s = s.clone before s.play
Personally I’d air on the side of it being a bug worthy of a feedback ticket as its performing differently than in windows.
Sorry folks:
I just tested the shared code 'as is" and I get a long sound, not one, nor twwo nor
The code works fine
Xojo 2015r1
macOS El Capitan