|
-
Nov 8th, 2006, 12:21 PM
#1
Thread Starter
Lively Member
[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:
Dim media As New System.Media.SoundPlayer
media = My.Resources.Beethoven_s_Symphony_No__9__Scherzo_
media.Play()
I just need a simple bit of code. Thanks
-
Nov 8th, 2006, 12:38 PM
#2
Thread Starter
Lively Member
Re: [2005] Playing Sounds
VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
My.Computer.Audio.Play(My.Resources.Beethoven_s_Symphony_No__9__Scherzo_, AudioPlayMode.Background)
End Sub
That didn't work either. InvalidOperationException error..
-
Nov 8th, 2006, 05:03 PM
#3
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.
-
Nov 8th, 2006, 05:53 PM
#4
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:
Dim MySound1 As New Microsoft.DirectX.AudioVideoPlayback.Audio("c:\test5.mp3")
Dim MySound2 As New Microsoft.DirectX.AudioVideoPlayback.Audio("c:\test5.mp3")
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MySound1.Play()
If CInt(TextBox1.Text) = 0 Then
Exit Sub
End If
System.Threading.Thread.Sleep(TextBox1.Text)
MySound2.Play()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
MySound1.Stop()
MySound2.Stop()
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|