ExclamationHelphow to make music play automatically when open program ?

Posts 1–9 of 9 · Page 1 of 1
how to make music play automatically when open program ?
how to make music play automatically when open program ?
.NET only provides extension support for WAV or WAVE (click here for Wiki reference)ⓘ media files. First of all you'll need to import the 'Media' namespace.

Code:
Imports System.Media
Create an instance of the 'SoundPlayer' class with the media file and use the form's 'Load' event to play it.

Code:
Private Sub Form1_Load() Handles MyBase.Load
    Dim SP As New SoundPlayer("SoundLocation")
    SP.Play()
End Sub
If you want the media to finish without interruption, use 'PlayAsync' function instead.
i got converter to MAV. I just don know how to make it play automatically when open .
Thanks for help
I have a way of my own i will post it soon without the need to convert or download the music
Quote Originally Posted by jins3xy97 View Post
how to make music play automatically when open program ?
You can do one of two things:
-First One: Do what @Geometrical said.


Quote Originally Posted by Geometrical View Post
.NET only provides extension support for WAV or WAVE (click here for Wiki reference)ⓘ media files. First of all you'll need to import the 'Media' namespace.

Code:
Imports System.Media
Create an instance of the 'SoundPlayer' class with the media file and use the form's 'Load' event to play it.

Code:
Private Sub Form1_Load() Handles MyBase.Load
    Dim SP As New SoundPlayer("SoundLocation")
    SP.Play()
End Sub
If you want the media to finish without interruption, use 'PlayAsync' function instead.

-Second way: Use this code (only plays .wav extension files since it's the only file that .NET provides extension support.):


  • Playing System Sounds:

ex.
Code:
My.Computer.Audio.PlaySystemSound(System.Media.SystemSounds.Asterisk)



  • Playing Music from your computer(I would advise you to add it to resources, easier.):


Code:
My.Computer.Audio.Play("PathToMusic")


Since you want to play it on Program Start-Up, place it on:

Code:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load 
My.Computer.Audio.Play("PathToMusic")
*code*
End Sub
Hope this was helpful.

EDIT: You can also use AudioPlayMode.BackgroundLoop to play it on the background & adding a loop to it.
Code:
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.
Or you could just attach it to your procces But still using code is better, but takes longer to do...
u can use this code

My.Computer.audio.play("C:\path\path",audioplaymod e.backgroundloop)
or this if u put it in the resources
my.computer.audio.play(my.resources.namename,audio playmode.backgroundloop
or go there
http :/ / msdn .microsoft. com/ en-us/ library/ 6y3efyhx (v=vs.90) .aspx
How to play MP3 and other sound files
Hello jins3xy97,

First of all you decide if you wanna loop the music or not.
I will post both ways.

With loop:
First you bind the sound file you wanna play in your resources.
Then you declare the mp3 path, the mp3 currentPlayPos, full lengths and a mp3Timer.

Code:
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"
Then you write this play function
Code:
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
Then command sender function
Code:
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
And the code to stop your music
Code:
Public Sub stopMusic(ByVal sAlias As String)
        mciSendString("stop " & sAlias, 0, 0, 0)
        mciSendString("close " & sAlias, 0, 0, 0)
End Sub
So then we are setup your mp3:
Code:
Private Sub setupMP3()
      My.Computer.FileSystem.WriteAllBytes(mp3, My.Resources.theMP3, False)
      File.SetAttributes(mp3, vbHidden)
End Sub
Goto FormLoad and write this.
Code:
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
Next your need the Timer tick method from your timer and write this.
Code:
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
Thats it, your mp3 should play in a loop.

Without loop:
Code:
Because i am too lazy too write again:
Just dont use the timer method and it will play once.
Greetings
Flaflo
Posts 1–9 of 9 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?