Answered Audio Files

PRo-Beaniie

Well-known member
Joined
Mar 17, 2011
Messages
55
Location
Hertford, Hertfordshire, United Kingdom
Programming Experience
3-5
Hey Guys,

Im trying to play a mp3 on my main menu for my game however its not playing...:confused:
ive tried hardcoding the file to the desktop, inserting the file into the solurtion explorer and even declaring it its own sub but i get no sound any ideas ??:confused:

I just want the file to play when the form loads up
 
Last edited:
Are you looking for something like this:

VB.NET:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    My.Computer.Audio.Play("C:\audiofile.wav")
End Sub
 
Oops, didn't see the MP3 part, my code won't work for that.
 
This Would Not Work...

Playing the audio file through direct x would not work through my colleges system so i cant use this method. But this is only because the college wouldnt have this software installed... are you sure there not a simpler way to do this with VB.Net 2010 :confused:
 
I have just converted my audi file from a mp3 to a WAV and its still not playing when the form loads heres the code but i cant see any errors ...

VB.NET:
Private Sub Menu_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Splash Screen Load 
        LoadScreen.ShowDialog()
        If Me.Visible = True Then
            My.Computer.Audio.Play("Audio Music.wav")
        End If
    End Sub
 
The reason that the above code isn't working is because Me.Visible = False in the form's load event. The load event occurs before the form is shown, so the form is not visible until after it is loaded.
 
AHAAAA life at last thank you for your help guys..... i moved it from event load and put it into a button howver this now means that the user has to click the button when ever he/she whants to hear the tune is there any other way to makt the audio start when the form becomes visible...?
 
You could try playing the sound on the forms 'Shown' event.
 
Use something like this to loop:

VB.NET:
My.Computer.Audio.Play("Audio Music.wav", AudioPlayMode.BackgroundLoop)

And to stop the loop:

VB.NET:
My.Computer.Audio.Stop()
 
Glad to help!
 

Latest posts

Back
Top