Results 1 to 4 of 4

Thread: [2005] Playing Sounds

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2006
    Posts
    88

    [2005] Playing Sounds

    I really don't know what to do. I've taken a stab at it, I want to play the sound from Resources

    VB Code:
    1. Dim media As New System.Media.SoundPlayer
    2.         media = My.Resources.Beethoven_s_Symphony_No__9__Scherzo_
    3.         media.Play()

    I just need a simple bit of code. Thanks


    Cyanide & Happiness @ Explosm.net

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Oct 2006
    Posts
    88

    Re: [2005] Playing Sounds

    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
    2.  
    3.         My.Computer.Audio.Play(My.Resources.Beethoven_s_Symphony_No__9__Scherzo_, AudioPlayMode.Background)
    4.  
    5.     End Sub

    That didn't work either. InvalidOperationException error..


    Cyanide & Happiness @ Explosm.net

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Playing Sounds

    The SoundPlayer class and the My.Computer.Audio.Play method are for sounds in WAV format only, as the documentation states. I'm guessing that your sound resource is a midi, mp3, wma or something else. If that's the case you can use a media player component, e.g. Windows Media Player (with or without a UI), or you can get closer to the machine itself and use MCI, either directly or using a prebaked class, e.g. the Multimedia class available from the Mentalis.org link in my signature.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4
    Frenzied Member
    Join Date
    Mar 2005
    Location
    Sector 001
    Posts
    1,577

    Re: [2005] Playing Sounds

    You can also use (the) DirectX (SDK) to play things other than WAVs. I used it for a primitive Gho'uld style flanging voice effect (you know, the Stargate snakes)
    VB Code:
    1. Dim MySound1 As New Microsoft.DirectX.AudioVideoPlayback.Audio("c:\test5.mp3")
    2.     Dim MySound2 As New Microsoft.DirectX.AudioVideoPlayback.Audio("c:\test5.mp3")
    3.  
    4.  
    5.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    6.  
    7.         MySound1.Play()
    8.  
    9.         If CInt(TextBox1.Text) = 0 Then
    10.             Exit Sub
    11.         End If
    12.  
    13.         System.Threading.Thread.Sleep(TextBox1.Text)
    14.         MySound2.Play()
    15.  
    16.     End Sub
    17.  
    18.  
    19.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    20.  
    21.         MySound1.Stop()
    22.         MySound2.Stop()
    23.  
    24.     End Sub
    Last edited by Half; Nov 8th, 2006 at 05:57 PM.
    VB 2005, Win Xp Pro sp2

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