Results 1 to 12 of 12

Thread: winmm.dll? ... is there a quicker way to play sounds ?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Location
    UK
    Posts
    127

    Cool 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.

  2. #2
    Hyperactive Member
    Join Date
    Jun 2008
    Location
    Nowhere
    Posts
    427

    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
    "Programming is like sex. One mistake and you have to support it for the rest of your life." ~Michael Sinz


    Code Snippets/Usefull Links:
    WinRAR DLL|Vista Style Form|Krypton Component Library|Windows Form Aero|Parsing XML files|Calculate File's CRC 32|Download a list of files.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Location
    UK
    Posts
    127

    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

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Location
    UK
    Posts
    127

    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()

  5. #5
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    Re: winmm.dll? ... is there a quicker way to play sounds ?

    Hi,

    Here's another way how to play a .wav file:

    vb Code:
    1. Const SND_ASYNC As Integer = &H1
    2. Const SND_FILENAME As Integer = &H20000
    3. Const SND_NODEFAULT As Integer = &H2
    4. Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Integer, ByVal dwFlags As Integer) As Integer
    5.  
    6.  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    7. PlaySound(Application.StartupPath & "\Media\name of your file.wav", 0, SND_NODEFAULT Or SND_ASYNC Or SND_FILENAME)
    8. 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
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Location
    UK
    Posts
    127

    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 ?

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Location
    UK
    Posts
    127

    Re: winmm.dll? ... is there a quicker way to play sounds ?

    bump!

  8. #8
    Junior Member
    Join Date
    Aug 2008
    Location
    Pittsburgh
    Posts
    20

    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.

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Location
    UK
    Posts
    127

    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)

  10. #10
    Junior Member
    Join Date
    Aug 2008
    Location
    Pittsburgh
    Posts
    20

    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.

  11. #11
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    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.

  12. #12
    Hyperactive Member syntaxeater's Avatar
    Join Date
    Dec 2006
    Location
    Des Moines, IA
    Posts
    460

    Re: winmm.dll? ... is there a quicker way to play sounds ?

    VB Code:
    1. Private ofd As OpenFileDialog
    2.     Private player As Microsoft.DirectX.AudioVideoPlayback.Audio
    3.     Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    4.         ofd = New OpenFileDialog
    5.     End Sub
    6.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    7.         If player Is Nothing OrElse Not player.Playing Then
    8.             If ofd.ShowDialog = Windows.Forms.DialogResult.OK Then
    9.                 player = New Microsoft.DirectX.AudioVideoPlayback.Audio(ofd.FileName)
    10.                 player.Play()
    11.             End If
    12.         Else
    13.             player.Stop()
    14.         End If
    15.     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
  •  



Click Here to Expand Forum to Full Width