Hi Margaret, no probs. The pic and code was enough You need to change the "Type" of resource to "SOUND". In the resource editor, double-click on the "101" and you'll get an "Edit Properties" dialog. Just change the Type to "SOUND". The play code needs to be changed to suit:
VB Code:
Private Sub cmdPlaySound_Click() 'PlaySound. Resource file. SYNCHRONOUS ONLY.
Dim bytResFile() As Byte
bytResFile = LoadResData(101, "SOUND")
Call PlaySoundResMem(bytResFile(0), App.hInstance, SND_MEMORY Or SND_SYNC)
End Sub
("WAVE" also works)
BTW, this code will cause the app to "freeze" while the sounds are played - which is what I assume you want for a Quiz program ie - stop user interaction until the questions/answers are played. As Arne Elster pointed out above, a minor change can alter this behaviour - the only problem being that the "sound file" stored in "bytResFile()" will remain in memory for the duration of the app. Although it can be erased, there is no easy (one liner) way to do this automatically - although it is possible. A better way is to use code that doesn't involve this overhead - the problem being it will only play sounds after you've made an exe. It won't play in the IDE If you want this alternative, just let me know.
Hi Margaret, no probs. The pic and code was enough You need to change the "Type" of resource to "SOUND". In the resource editor, double-click on the "101" and you'll get an "Edit Properties" dialog. Just change the Type to "SOUND". The play code needs to be changed to suit:
VB Code:
Private Sub cmdPlaySound_Click() 'PlaySound. Resource file. SYNCHRONOUS ONLY.
Dim bytResFile() As Byte
bytResFile = LoadResData(101, "SOUND")
Call PlaySoundResMem(bytResFile(0), App.hInstance, SND_MEMORY Or SND_SYNC)
End Sub
("WAVE" also works)
The audio file name is "Welcome.wav". I put this file in Resource Folder. I am still confused since it doesn't play the sound.
Try the project in this zip file. Very, very rarely, PlaySound fails on some PCs. Let me know if it works OK.
EDIT: Attachment removed. See later post.
Last edited by schoolbusdriver; Nov 13th, 2006 at 03:03 PM.
The audio file name is "Welcome.wav". I put this file in Resource Folder. I am still confused since it doesn't play the sound.
Providing you have Type right = "SOUND" and the ID is a number you may have problems hearing the sound in IDE. Compile the exe and try it again.
schoolbusdriver gave me different code to play wave files and I had to compile before I could hear a sound.
Keith
I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.
Providing you have Type right = "SOUND" and the ID is a number you may have problems hearing the sound in IDE. Compile the exe and try it again.
schoolbusdriver gave me different code to play wave files and I had to compile before I could hear a sound.
Hi,
Still, I am confused. Suppose I have 10 audio files in a folder "Audio Songs" say, Song1, Song2, Song3 ......Song10, and the folder is in the same project folder. How can I listen to a song Song1 when I click on cmdSong1.
Kindly let me know the easiest way to do this, please.
When you add these songs to a resource file I normally use the filename without the extension. Because that is easy to play that sound. But if you are using schoolbusdriver code with PlaySound API you need to change this to a number so write them down.
Call PlaySound(SoundBuffer, App.hInstance, SND_RESOURCE Or SND_ASYNC)
End Sub
Private Sub cmdSong1_Click()
Call PlaySounds(101)
End Sub
Are your sound types "SOUND"?
Last edited by Keithuk; Nov 11th, 2006 at 06:07 PM.
Keith
I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.
Well have I said before I can't hear any sounds using PlaySound API on my comp you have to compile the exe first then run the exe.
Keith
I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.