Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27046

VB Sound help

$
0
0
Hi im in the procces of making a very simple game in vb, anyways my problem is after using directx api to play my background sounds(it works fine), i have it setup so that when the user clicks a button on my first form that play back will stop, but for some reason its not working. the mp3 just keeps playing in the background, and then mixes up with other background mp3 i have set up, and the sound is a total mess. any help will be gladly appreciated.

Code:

Imports Microsoft.DirectX.AudioVideoPlayback
Imports Microsoft.DirectX.DirectSound
Imports Microsoft.DirectX
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim mp3 As Audio = New Audio("C:\Users\theunholy\Desktop\juegoimple\juegoimple\Resources\music.mp3")
        My.Computer.Audio.Play(My.Resources.click, AudioPlayMode.Background)
        RemoveHandler mp3.Ending, AddressOf Me.MusicEnds
        mp3.Stop()
        mp3.Dispose()
        mp3 = Nothing
        Form2.Show()
        Me.Hide()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        My.Computer.Audio.Play(My.Resources.click, AudioPlayMode.Background)
        Form3.Show()
        Me.Hide()
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        My.Computer.Audio.Play(My.Resources.click, AudioPlayMode.Background)
        Application.Exit()
        Me.Hide()
    End Sub
    Private Sub MusicEnds(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim mp3 As Audio = New Audio("C:\Users\theunholy\Desktop\juegoimple\juegoimple\Resources\music.mp3")
        mp3.CurrentPosition = 0
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        FormBorderStyle = Windows.Forms.FormBorderStyle.None
        Dim mp3 As Audio = New Audio("C:\Users\theunholy\Desktop\juegoimple\juegoimple\Resources\music.mp3")
        AddHandler mp3.Ending, AddressOf Me.MusicEnds
        mp3.Play()
    End Sub
End Class


Viewing all articles
Browse latest Browse all 27046

Trending Articles