Playing two sounds at once

Sprint

Well-known member
Joined
Feb 3, 2006
Messages
58
Location
Ohio
Programming Experience
5-10
I have app that has a background sound and a sound when someone clicks something. But when they click the something it stops the background sound, which is supposed to loop. How can I play both sounds and leave the background looping? Heres a example of the code:

VB.NET:
    Private WheelTickSound As Media.SoundPlayer = New Media.SoundPlayer("Sounds\tick.wav")
    Private BackgroundSound As Media.SoundPlayer = New Media.SoundPlayer("Sounds\BackgroundMusic.wav")

    Private Sub GameBoard_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        WheelTickSound.Load()
        BackgroundSound.Load()
        BackgroundSound.PlayLooping()
    End Sub

    Private Sub SpinWheel()
        WheelTickSound.Play()
    End Sub

So the form loads and loads the two wav files then starts playing the background clip in a loop. But when someone clicks on a button that executes the "SpinWheel" routine the WheelTick sound plays but stops the background music. How can I make it keep playing?

-Allan.
 
You can't play two wave sounds at the same time. Even Windows itself doesn't do that. You'd need to have two sound cards to play two wave files. You might want to look into having your background music be some other format that can be played while you play a wave file. I'm 95% sure that what I've said is correct.
 
Hi
It is possible to play two wav files at once but not through the same instance of the application (to test open up two wav players and play).
I'm not sure of the best way of doing this but i would sugest creating a seperat thread for the background music.
E.G.

VB.NET:
Private Sub GameBoard_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim thrProcess As New Thread(AddressOf Me.playBackgroundMusic)
        thrProcess.Name = "BackgroundThread"
        thrProcess.Start()
        WheelTickSound.Load()
    End Sub
   
    private sub playBackgroundMusic()     
        BackgroundSound.Load()
        BackgroundSound.PlayLooping()
        while mIsRunning = true 
            thread.sleep(1000)
        end while
    end sub

    Private Sub SpinWheel()
        WheelTickSound.Play()
    End Sub
g
 
jmcilhinney said:
You can't play two wave sounds at the same time. Even Windows itself doesn't do that. You'd need to have two sound cards to play two wave files. You might want to look into having your background music be some other format that can be played while you play a wave file. I'm 95% sure that what I've said is correct.
From another forum I believe your correct unless you get DirectX involved. With that said the nice and easy soundplayer only seems to accept wav files and this project is not supposed to be that involved so I guess I'll have to just live without background music.

fomhoire said:
It is possible to play two wav files at once but not through the same instance of the application (to test open up two wav players and play).
I'm not sure of the best way of doing this but i would sugest creating a seperat thread for the background music.

I tried using a background worker which should run on another thread but it didn't work either. I'll try playing with your example and see if it makes a difference. (Edit: no...still same results)

-Allan.
 
Last edited:
Back
Top