Hello all,
Well, i got inspired with the bunch of tutorials availalbe in this website, and i'm interested to post my findings too.......
Well this time we will try to design a program which satisfies the following requirements.
QUOTE
We want to create a project which plays a sound file now and then to alert the user or to give a cool experience with some songs..... now you have got the answer......
Because i found this very handy..... felt it must help our other team member also.........
Create a new project in vb.net windows application.keep a test file of some wav file in c:\test\files\welcome.wav (or some other...)
(your project can be saved in any location)
Place 2 buttons on the Form
Go to Project --> Resources --> Add existing File --> Select Audio File --> Select the welcome.wav file and add it.
Now place the code in the buttons
Button1
This plays the file system wav file.
CODE
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
My.Computer.Audio.Play("c:\test\files\welcome.wav")
End Sub
Button2
This plays the wav file embedded in the Resources File
CODE
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If My.Resources.welcome.CanRead Then
Dim bStr(My.Resources.welcome.Length) As Byte
My.Resources.welcome.Read(bStr, 0, My.Resources.welcome.Length)
My.Computer.Audio.Play(bStr, AudioPlayMode.Background)
End If
End Sub
Remember to import the following in case required.
QUOTE
Imports System.IO
Thats it.
You have done it.
Now press the Button1 : It will play the sound file from the harddisk.
Now press the Button2 : It will play the sound file from the embedded Resources file !
Enjoy.......