Link to home
Start Free TrialLog in
Avatar of Theo Kouwenhoven
Theo KouwenhovenFlag for Netherlands

asked on

Playing MP3 with VB6

Hi Experts,

Can you advise me what i need to play MP3 files from VB6
please not to complex, I'm still a newbie in VB :)


Regards,
Murph
Avatar of JackOfPH
JackOfPH
Flag of Philippines image

Assalam-o-Alaikum Chudzidiot
      Here is the answer regarding to your question in which you said for code to play .MP3 song by VB5/6 coding. This code is working very well. Let’s try and give me feed back. You may run any file which have any format like .MP3, .WAV etc. You can use text2.text value for progress bar change. If you can’t do it, then reply, I will do it for you…. Thanks

Steps:-
      1:  Start new project (form1 will be automatically add)
      2: Add two command buttons automatically named to “command1” & “command2”
      3: Add two text boxes automatically named to “text1” & “text 2”
      4: Add a timer control automatically named to “timer1”, set its “interval” to 500, and “enabled” property to false.
      5: Paste all this code in form’s code window
      6: Change the file path name in  {Form1.FilePath = "D:\MP3SONGS\BAS.MP3"} line as required.
      6: Save the project and run.
     

‘Code Starts From Here
‘---------------------------
Option Explicit
Private Declare Function mciSendStringA Lib "winmm.dll" _
(ByVal lpstrCommand As String, ByVal _
lpstrReturnString As String, ByVal uReturnLength As Long, _
ByVal hwndCallback As Long) As Long

Public Temp As Integer, ReturnString As String, FilePath As String, Abc As Variant

Public Function SendMCIcommand(TheCommand As String) As String
    ReturnString = String$(128, " ")
    Temp = mciSendStringA(TheCommand, ReturnString, 127, 0)
    SendMCIcommand = ReturnString
End Function

Private Sub Command1_Click()
    Form1.FilePath = "D:\MP3SONGS\BAS.MP3"
    Form1.Abc = SendMCIcommand("open " & Form1.FilePath)
    Form1.Abc = SendMCIcommand("play " & Form1.FilePath)
    Form1.Timer1.Enabled = True
End Sub

Private Sub Command2_Click()
    Form1.Abc = SendMCIcommand("close " & Form1.FilePath)
    Form1.Timer1.Enabled = False
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Unload form1
End Sub

Private Sub Timer1_Timer()
    Form1.Text1.Text = SendMCIcommand("status " & Form1.FilePath & " length")
    Form1.Text2.Text = SendMCIcommand("status " & Form1.FilePath & " position")
End Sub

‘---------------------------
 ‘Code Ends To Here
Avatar of Theo Kouwenhoven

ASKER

Hey JackOfPH,

looks good, but is there a way to skip to a specific point in a mp3?
is there volume controll that is secific for this object,
so if I create SendMCIcommand1 and SendMCIcommand2 thet they will not interfere?

Thanks already !!!

Regards,
Murph
I think you have to create your own class for this...

ASKER CERTIFIED SOLUTION
Avatar of JackOfPH
JackOfPH
Flag of Philippines image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
creating classes is not something a newbie  can do :(

I'm now trying to use "ActiveMovie control Library"
but strugeling with an incorrect duration time :(
Not the right answer, but if brought me to find a solution with 'active Movie Control'