Reputation: 31
I'm polishing a VB.NET hangman game. I added the sound of a turkey gobbling when you win the game. This is in my loop for when you win:
Dim sndPing As New SoundPlayer(My.Resources.turkey)
sndPing.Play()
My.Computer.Audio.Play("C:\Users\john\Desktop\CS120_FinalProject_Hannonv2.0\CS120_FinalProject_Hannonv1.5\FinalProject_Hangman_Hannon\FinalProject_Hangman_Hannon\Resources\turkey.wav", AudioPlayMode.Background)
I have loaded the turkey.wav file into my resources, but I cannot give it a local directory with the "\Resources\turkey.wav" or My.Resources.turkey. I'm trying to find a way to send the file when I package it.
Upvotes: 3
Views: 36220
Reputation: 1151
Easy, if your resource audio file is called "Ding"
My.Computer.Audio.Play(My.Resources.Ding, AudioPlayMode.Background)
That's all folks! :)
Upvotes: 15
Reputation: 3069
Your code is doing the same thing twice. First you create a SoundPlayer object with an embedded resources, and then you are calling the static function "My.Computer.Audio.Play". You will want to do one or the other.
The advantage with the SoundPlayer is you can use an embedded resource (so you don't have to track the wav file down). But it does require a bit more setup.
If you want to use the static function, you can pass in a path relative to your exe location. Something like this:
My.Computer.Audio.Play(System.AppDomain.CurrentDomain.BaseDirectory & "\turkey.wav")
Note that your wav file will need to be in the same folder as your .exe for the above code to work.
Upvotes: 5