whats the best+quickest way to play wav files/mp3s in vb.net
im currently using winmm.dll and it really slows my app down
is there a better way of doing this ?
many thanks
illskills
Printable View
whats the best+quickest way to play wav files/mp3s in vb.net
im currently using winmm.dll and it really slows my app down
is there a better way of doing this ?
many thanks
illskills
Have you tried running it in a sepearate thread? and you can try the Windows Media player 11 SDK? http://msdn.microsoft.com/en-us/libr...57(VS.85).aspx
ive never looked at threading ill check it out ... its about time lol
im gonna hit google up
Right i tried threading the function but it seems to slow the app the first time the sound is played ... then if played in succession after the initial sound it plays fine
if the sound if played once every 3/5+ seconds it slows my app down ?
the wav file is only 2kb ?
threaded it like so ...
Dim MySFX As New System.Threading.Thread(AddressOf PlayWave)
MySFX.Start()
Hi,
Here's another way how to play a .wav file:
vb Code:
Const SND_ASYNC As Integer = &H1 Const SND_FILENAME As Integer = &H20000 Const SND_NODEFAULT As Integer = &H2 Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Integer, ByVal dwFlags As Integer) As Integer Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load PlaySound(Application.StartupPath & "\Media\name of your file.wav", 0, SND_NODEFAULT Or SND_ASYNC Or SND_FILENAME) End Sub
The only thing you have to do is create a media folder into your Bin folder and put your .wav file into it.
Then use this code.
Hope it helps,
sparrow1
ez sparrow thats the method im using ... it works but slows my game down when i call ... it is there anyway to load sounds into memory and play them, rather than reading the file each time ?
bump!
Right now I am toying with DirectSound (DirectX SDK required). It's pretty snappy and it sounds good. Has LOTS of functionality....However... I can't seem to find ANY support. But playing sounds in DirectSound is pretty simple.
when i was using c++ i found a library called fsound which i used with some opengl apps this was very useful but i dont know if it would work in vb.net ... and im currently downloading directx v9
i have a 2D game engine working now just need to write a 3D front end and add sound lol
ill have a look @ that direct sound function as soon as i've installed dx9
thanks for your help, nice one
;0)
Hey no problem. If you have problems finding source for playing a sound in DirectSound lemme know I'll link you. And don't worry your not alone when it comes to not being able to find source code for DirectSound.
You should actually use Sytem.Media and more specifically the SoundPlayer class to play wav files.
VB Code:
Private ofd As OpenFileDialog Private player As Microsoft.DirectX.AudioVideoPlayback.Audio Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load ofd = New OpenFileDialog End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If player Is Nothing OrElse Not player.Playing Then If ofd.ShowDialog = Windows.Forms.DialogResult.OK Then player = New Microsoft.DirectX.AudioVideoPlayback.Audio(ofd.FileName) player.Play() End If Else player.Stop() End If End Sub
3 things:
1 - Add a reference to Microsoft.DirectX.AudioVideoPlayback
2 - If you are running on a x64 operating system, you need to go into compile and set target CPU to x86.
3 - This is prone to throw a OS Loader Lock exception during debug only. If you run this from the exe, there is no issue. To get around it, go into Debug >> Exceptions >> Managed Debug Assistants >> and uncheck LoaderLock..