how to make music play automatically when open program ?
how to make music play automatically when open program ? 








Imports System.Media
Private Sub Form1_Load() Handles MyBase.Load
Dim SP As New SoundPlayer("SoundLocation")
SP.Play()
End Sub

My.Computer.Audio.PlaySystemSound(System.Media.SystemSounds.Asterisk)
My.Computer.Audio.Play("PathToMusic")
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
My.Computer.Audio.Play("PathToMusic")
*code*
End Sub

My.Computer.Audio.Play("PathToMusic", AudioPlayMode.BackgroundLoop)'Plays music in background & loops it.
My.Computer.Audio.Play("PathToMusic", AudioPlayMode.Background)' Plays music in background (Doesn't loop).
My.Computer.Audio.Play("PathToMusic", AudioPlayMode.WaitToComplete)' Plays music & Only after it stops does the code continue.
My.Computer.Audio.Stop()'Add this code when you want to stop it.
But still using code is better, but takes longer to do...Dim WithEvents mp3Timer As New Timer Dim lCurPos As Long Dim lLength As Long Dim current As String = My.Computer.FileSystem.CurrentDirectory + "\" Dim musicAs String = current + "music.mp3"
Public Function playMusic(ByVal sFile As String, _
ByVal sAlias As String) As Boolean
Dim bResult As Boolean
Dim sBuffer As String
Dim lResult As Long
sBuffer = Space$(255)
lResult = GetShortPathName(sFile, sBuffer, Len(sBuffer))
If lResult <> 0 Then
sFile = Microsoft.VisualBasic.Left(sBuffer, InStr(sBuffer, vbNullChar) - 1)
lResult = mciSendString("open " & sFile & _
" type MPEGVideo alias " & sAlias, 0, 0, 0)
If lResult = 0 Then
If mciSendString("play " & sAlias & _
" from 0", 0, 0, 0) = 0 Then
bResult = True
End If
End If
End If
playMusic = bResult
End Function
Private Function SendCommand(ByVal sCmd As String) As Long
Dim lResult As Long
Dim sReturn As String
sReturn = Space$(256)
lResult = mciSendString(sCmd, sReturn, Len(sReturn), 0&)
SendCommand = Val(sReturn)
End Function
Public Sub stopMusic(ByVal sAlias As String)
mciSendString("stop " & sAlias, 0, 0, 0)
mciSendString("close " & sAlias, 0, 0, 0)
End Sub
Private Sub setupMP3()
My.Computer.FileSystem.WriteAllBytes(mp3, My.Resources.theMP3, False)
File.SetAttributes(mp3, vbHidden)
End Sub
Private Sub Form_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
setupResources()
playMusic(mp3, "mp3Loop")
mp3Timer.Start()
End Sub
Private Sub mp3Timer_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles mp3Timer.Tick
lCurPos = SendCommand("status mp3Loop position")
lLength = SendCommand("status mp3Loop length")
If lCurPos >= lLength Then
SendCommand("play mp3Loop from 0")
End If
End Sub
Because i am too lazy too write again: Just dont use the timer method and it will play once.
