Playing a sound file

This may have been answered before i am not sure, i am running Visual Studio 2005 beta,
i would like to know how i can play a sound file in the background when someone opens a form. Any ideas




Answer this question

Playing a sound file

  • Dean S.

    I am using the my.computer.audio.play function to play an alert.

    The alert is the result of checking a database for new entries every 10 seconds. If there is a new entry that the software has not seen yet, it uses the VBPower Tools Notification Window to pop-up a message.

    What I want this to do is play the audio at that same time.

    My problem is, I am unable to get audio to play inside of a timer's tick event handler.

    Does anyone have any suggestions on how I can get audio to kick off inside that routine

    Thanks!

    Chris


  • MrZkitten

    SoundPlayer is a regular class, and has to be initialized:



    Dim s As New System.Media.SoundPlayer(filename)
    s.Load()
    s.Play()

     


  • jagadisha

    yeah sorry about that, i have recently solved it, but thank you very much if you hadn't had given the small snippet of code i would be still wondering about it.
    Thanks!

    Andrew

  • pradjini

    If you have Visual Studio 2005, you don't need to download anything.

    What error message do you get Keep in mind that SoundPlayer only supports wav files, no mp3...

  • Andreas Masur

    VB.NET 2005

    Top play an audio file. Extremely simple using the new My functionality.

    My.Computer.Audio.Play("c:\windows\media\chime.wav")

    My.Computer.Audio.Stop()

    To stop the audio when the form visibility changes to hidden then something like this should work.

    [code language="vb"]

    Private Sub Form1_VisibleChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.VisibleChanged

    If Me.Visible = False Then

    My.Computer.Audio.Stop()

    End If

    End Sub

    [/code]

    For course if your using another approach to playing the audio (using the

    System.Media.SoundPlayer) you can put in the stop method line in place of the my.computer.audio.stop method.


  • harolds

    Sorry to be a annoying,
    But do you know how i can stop the sound from playing when i make the form visible = false
    i haven't been able to work that part out yet!



  • zgueney

    I'm not able to find a reference to this myself, but this is a good question.  How do you create a system event sound in windows and then invoke it   What's more efficient for playing a wav with your application...invoking a system event sound or just doing the my.computer.audio.play

    Thanks

    Ted Wagner
    http://www.trwagner.org
    http://www.hanggup.com


  • AngryRichard

    i have followed the link but there are no mention of anything to download or anything like that. I have tried some of the coding found of the page, for example

    media.soundplayer

    but it always returns an error message

  • invc

     Ted Wagner wrote:

    I'm not able to find a reference to this myself, but this is a good question.  How do you create a system event sound in windows and then invoke it   What's more efficient for playing a wav with your application...invoking a system event sound or just doing the my.computer.audio.play

    Thanks

    Ted Wagner
    http://www.trwagner.org
    http://www.hanggup.com

     

    Think I found it:

     

    My.Computer.Audio.PlaySystemSound()

    Ted Wagner
    http://www.trwagner.org
    http://www.hanggup.com

     


  • Tommy Williams - MSFT

    Ok i am going to probably sound really thick here,
    say i have a wav file in my documents

    what do i place in the brackets between s.load() and s.play()

    Sorry i am completely new to this level of coding!

  • *George*

    What about System.Media.SystemSounds.Beep.Play();

    or just System.Media.SystemSounds.Beep() in VB


  • KrazyMGA

  • nuAnonymous

    This is the error message i get up when i try

    media.soundplayer

    i may be typing something wrong i don't any help would be good!


    Error 1 'SoundPlayer' is a type in 'Media' and cannot be used as an expression


  • dicksters

    Nothing, that's just what I do when I call a method. C# enforces you to do that, in VB you can just write s.Load and s.Play

  • Playing a sound file