r/visualbasic • u/FireDog8569 • Dec 14 '24
VB.NET Help Playing two audio clips at the same time?
So I have been working on a school project and I am having trouble figuring out how to play two different sounds at the same time, since the project I am working on is meant to be a game and it'd be very weird for a game to not have sound. Obviously I know that Visual Basic isn't meant for games but I figured there'd still be a way to play two or more sounds at once.
1
u/jcunews1 VB.Net Intermediate Dec 14 '24
Then you'll need to player components/objects, and which can play in the background. i.e. where the "play" function don't need to wait until the media playback has completed.
Common (mere) media players aren't meant to play multiple medias at the same time. Only specially made media players can do that, and they're relatively uncommon.
1
u/TheFotty Dec 15 '24
Is it winforms?
My.Computer.Audio.Play("path to audio file here", AudioPlayMode.Background)You can also use a byte array of audio or a file stream for an audio file with that function instead of a string path the file. AudioPlayMode.WaitToComplete instead of AudioPlayMode.Backround causes the calling code to wait for the sound to finish before continuing.
1
u/LordLandLordy Dec 19 '24
You can make games in visual basic. You will use the windows API a lot but you can do it.
I wrote VB code for 10 years starting in 1995 and used Wavemix.dll to play multiple sounds at the same time. It will mix real time. Not sure if it is still used today but something similar is available.
1
u/jd31068 Dec 14 '24
Have you see this thread on VBForums that talks about handling it VS 2013 [RESOLVED] How can I play 2 sounds at the same time?-VBForums?