Welcome to Dream.In.Code
Getting Help is Easy!

Join 132,103 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,247 people online right now. Registration is fast and FREE... Join Now!




Playing Sound Files for your Project...

 
Reply to this topicStart new topic

> Playing Sound Files for your Project..., A small project which plays Sound files from file system or from Resou

Rating  5
jagatworld
Group Icon



post 28 Jun, 2008 - 10:19 PM
Post #1


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. smile.gif

You have done it. icon_up.gif

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.......
cool.gif



Go to the top of the page
+Quote Post


Register to Make This Ad Go Away!


Fast ReplyReply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 11/21/08 09:30AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month