-
Aug 11th, 2008, 08:54 PM
#1
Thread Starter
Lively Member
winmm.dll? ... is there a quicker way to play sounds ?
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
Last edited by illskills; Aug 11th, 2008 at 09:25 PM.
-
Aug 11th, 2008, 09:02 PM
#2
Hyperactive Member
Re: winmm.dll? ... is there a quicker way to play sounds ?
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
-
Aug 11th, 2008, 09:15 PM
#3
Thread Starter
Lively Member
Re: winmm.dll? ... is there a quicker way to play sounds ?
ive never looked at threading ill check it out ... its about time lol
im gonna hit google up
-
Aug 11th, 2008, 09:29 PM
#4
Thread Starter
Lively Member
Re: winmm.dll? ... is there a quicker way to play sounds ?
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()
-
Aug 12th, 2008, 03:55 AM
#5
Re: winmm.dll? ... is there a quicker way to play sounds ?
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
-
Aug 12th, 2008, 06:00 AM
#6
Thread Starter
Lively Member
Re: winmm.dll? ... is there a quicker way to play sounds ?
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 ?
-
Aug 12th, 2008, 04:05 PM
#7
Thread Starter
Lively Member
Re: winmm.dll? ... is there a quicker way to play sounds ?
-
Aug 12th, 2008, 04:35 PM
#8
Junior Member
Re: winmm.dll? ... is there a quicker way to play sounds ?
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.
-
Aug 12th, 2008, 07:39 PM
#9
Thread Starter
Lively Member
Re: winmm.dll? ... is there a quicker way to play sounds ?
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)
-
Aug 12th, 2008, 07:51 PM
#10
Junior Member
Re: winmm.dll? ... is there a quicker way to play sounds ?
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.
-
Aug 12th, 2008, 08:01 PM
#11
Re: winmm.dll? ... is there a quicker way to play sounds ?
You should actually use Sytem.Media and more specifically the SoundPlayer class to play wav files.
-
Aug 12th, 2008, 09:00 PM
#12
Re: winmm.dll? ... is there a quicker way to play sounds ?
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..
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|