[Help]how to open mp3 files?

Posts 114 of 14 · Page 1 of 1
[Help]how to open mp3 files?
Yes I know how to play them... I want to make a mp3 player that you can use as a default player

so I ask how to open a mp3 with my project and add it to a listbox

Tips? Resources? (Google isn't one) Anything? Thank you for any help.
Ok, So you know how to play mp3's from "within" your application, you are looking to load the Mp3's into a listbox to be added into a ordered list to be played from?

If that is the case, here are some ideas.

First, answer, to add a MP3 to a listbox one at a time or multiple sections from a single folder ot location.

Code:
    Dim mp3file As New List(Of String)


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        On Error Resume Next
        Dim Ofile As New OpenFileDialog
        Ofile.Multiselect = True
        Ofile.Title = "Add Music Files"
        Ofile.Filter = "Mp3 Files |*.mp3"
        Ofile.FileName = ""
        Ofile.ShowDialog()


        For Each track As String In Ofile.FileNames
            mp3file.Add(track)
            ListBox1.Items.Add(track.Substring(track.LastIndexOf("\") + 1))
        Next
    End Sub



Then play from file path.

I also suggest (for a more advanced player) you add the ability to add directories and allow your application to search the directories for file types, along with search the entire machine.

If you decide to search the machine, use multi threading and set it to the background.
Thanks but I have this already

I want to make default player aka you just click on a mp3 and it opens my player then adds the url to a list
Mp3 player created using the windows media player 7 control. It allows you to create, load, and save lists of mp3 songs to play.

Code:
Option Explicit

Private Sub Add_Click()
Dim sfile As String
With Dialog
    .CancelError = False
    .Filter = "Mp3 files|*.mp3;"
    .ShowOpen
    If .FileName = "" Then
    Exit Sub
    ElseIf Not LCase$(Right$(.FileName, 4)) = ".mp3" Then
    Exit Sub
    End If
End With
    sfile = Dialog.FileName
    Dialog.FileName = ""
    List1.AddItem sfile
    sfile = ""
End Sub

Private Sub Back_Click()
    Dim spev As String
If last < 1 Then
Exit Sub
End If
    last = last - 1
    spev = List1.List(last)
    List1.ListIndex = List1.ListIndex - 1
    Play.FileName = spev
    Play.Play
    plays = ""
    Slider1.Max = Play.Duration
    Songname.Caption = List1.Text
End Sub

Private Sub cmdplay_Click()
On Error Resume Next
    Play.FileName = List1.Text
    Play.Play
    plays = ""
    Slider1.Max = Play.Duration
    Songname.Caption = List1.Text
End Sub

Private Sub Command1_Click()
VB.Unload Me
End
End Sub

Private Sub Command2_Click()
    Play.Stop
End Sub
Private Sub Command3_Click()
    On Error GoTo soo
    Dim snext As String
    last = last + 1
    snext = List1.List(last)
    List1.ListIndex = List1.ListIndex + 1
    Play.FileName = snext
    Play.Play
soo:
last = List1.ListIndex
 plays = ""
    Slider1.Max = Play.Duration
    Songname.Caption = List1.Text
End Sub

Private Sub Command4_Click()
Dim sfile As String
With Dialog
    .CancelError = False
    .Filter = "Mp3 Play list|*.mpl"
    .ShowOpen
    If .FileName = "" Then
    Exit Sub
    End If
    sfile = Dialog.FileName
    Dialog.FileName = ""
End With
    List1.Clear
Dim a As String
Dim X As String
On Error GoTo error
Open sfile For Input As #1
Do Until EOF(1)
Input #1, a$
List1.AddItem a$
Loop
Close 1
sfile = ""
Exit Sub
error:
X = MsgBox("File Not Found", vbOKOnly, "Error")

End Sub

Private Sub Command5_Click()
Me.WindowState = 1
End Sub


Private Sub Command6_Click()
    List1.Clear
End Sub

Private Sub Command7_Click()
    Image7_Click
End Sub

Private Sub Form_Load()
    plays = "stop"
    sloop = "False"
    Slider2.Value = 2500
    Dim sfile, a As String
    sfile = App.Path + "\" + "default.mpl"
    On Error GoTo serr
    Open sfile For Input As #1
    Do Until EOF(1)
    Input #1, a$
    List1.AddItem a$
    Loop
    Close #1
serr:
    Close #1
End Sub

Private Sub Form_Unload(Cancel As Integer)
Dim sfile As String
Dim i As Long
sfile = App.Path + "\" + "default.mpl"
On Error GoTo error
Open sfile For Output As #1
For i = 0 To 100
    List1.ListIndex = i
     Write #1, List1.Text
Next i
error:
    Close #1

End Sub

Private Sub Image7_Click()
   If frmmain.Height = 5715 Then
      frmmain.Height = 2085
   ElseIf frmmain.Height = 2085 Then
      frmmain.Height = 5715
   End If
End Sub

Private Sub Image8_Click()
frmAbout.Show vbModal
End Sub

Private Sub List1_DblClick()
    plays = "stop"
    Play.FileName = List1.Text
    Play.Play
    Slider1.Max = Play.Duration
    last = List1.ListIndex
    Songname.Caption = List1.Text
End Sub

Private Sub List1_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyDelete Then
        If List1.ListIndex = -1 Then
Else
    List1.RemoveItem List1.ListIndex
    End If
End If
End Sub

Private Sub mnumainclose_click()
End
End Sub

Private Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 2 Then
    Me.PopupMenu main
End If
End Sub

Private Sub Image1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = 1 Then
    FormDrag Me
    End If
End Sub

Private Sub open_Click()
Dim sfile As String
With Dialog
    .CancelError = False
    .Filter = "MP3 Files|*.mp3"
    .ShowOpen
End With
    If Dialog.FileName = "" Then
    Exit Sub
    ElseIf Not Right$(Dialog.FileName, 4) = ".mp3" Then
    Exit Sub
    End If
    sfile = Dialog.FileName
    Dialog.FileName = ""
Play.FileName = sfile
    List1.Clear
    List1.AddItem sfile
    Slider1.Max = Play.Duration
    sfile = ""
    List1.ListIndex = 0
    Songname.Caption = List1.Text
End Sub

Private Sub Pause_Click()
On Error Resume Next
  If Play.PlayState = 1 Then
    Play.Play
    Else
    Play.Pause
End If
End Sub

Private Sub Play_EndOfStream(ByVal Result As Long)
If Rep.BackColor = &HFF& Then
Exit Sub
Else: Play.Play
End If
End Sub

Private Sub Rem_Click()
    If List1.ListIndex = -1 Then
Else
    List1.RemoveItem List1.ListIndex
End If
End Sub

Private Sub Rep_Click()
    If Rep.BackColor = &HFF& Then
    Rep.BackColor = &HFF00&
    sloop = "True"
    ElseIf Rep.BackColor = &HFF00& Then
    Rep.BackColor = &HFF&
    sloop = "False"
    End If
End Sub

Private Sub Savelist_Click()
    Dim i As Long
    Dim sfile As String
With Dialog
    .CancelError = False
    .Filter = "Mp3 list|*.mpl"
    .ShowOpen
    If .FileName = "" Then
    Exit Sub
    End If
End With
    sfile = Dialog.FileName
    Dialog.FileName = ""
    On Error GoTo error
    Open sfile For Output As #1
For i = 0 To 100
    List1.ListIndex = i
     Write #1, List1.Text
Next i
error:
    Close #1
End Sub

Private Sub Slider1_Click()
        Play.CurrentPosition = Slider1.Value
End Sub

Private Sub Slider1_Scroll()
    Play.CurrentPosition = Slider1.Value
End Sub

Private Sub Slider2_Click()
    Play.Volume = Slider2.Value - 2500
End Sub

Private Sub Slider2_Scroll()
    Play.Volume = Slider2.Value - 2500
End Sub

Private Sub Timer1_Timer()
    Slider1.Value = Play.CurrentPosition
End Sub

Private Sub Timer2_Timer()
Dim tinseconden As Long
Dim lengths, lengths1, min, sec As Long
lengths = Play.Duration
tinseconden = Play.CurrentPosition
lengths1 = lengths - tinseconden
min = lengths1 \ 60
sec = lengths1 - min * 60
time.Caption = min & " : " & sec
End Sub
In order to use your player as default, do the following:

*Look for an MP3 file
*Right Click on it and select "open with"
*Select at the bottom "Choose program", a little window will pop up
*Press the browse button and look the ubication of your MP3 Player.
*When you find it, in the little window, click on the ckeckbox that says "run always with the selected program"
*Now you good to go

I hope this can help you
Quote Originally Posted by SmartAlley View Post
Mp3 player created using the windows media player 7 control. It allows you to create, load, and save lists of mp3 songs to play.

Code:
Option Explicit

Private Sub Add_Click()
Dim sfile As String
With Dialog
    .CancelError = False
    .Filter = "Mp3 files|*.mp3;"
    .ShowOpen
    If .FileName = "" Then
    Exit Sub
    ElseIf Not LCase$(Right$(.FileName, 4)) = ".mp3" Then
    Exit Sub
    End If
End With
    sfile = Dialog.FileName
    Dialog.FileName = ""
    List1.AddItem sfile
    sfile = ""
End Sub

Private Sub Back_Click()
    Dim spev As String
If last < 1 Then
Exit Sub
End If
    last = last - 1
    spev = List1.List(last)
    List1.ListIndex = List1.ListIndex - 1
    Play.FileName = spev
    Play.Play
    plays = ""
    Slider1.Max = Play.Duration
    Songname.Caption = List1.Text
End Sub

Private Sub cmdplay_Click()
On Error Resume Next
    Play.FileName = List1.Text
    Play.Play
    plays = ""
    Slider1.Max = Play.Duration
    Songname.Caption = List1.Text
End Sub

Private Sub Command1_Click()
VB.Unload Me
End
End Sub

Private Sub Command2_Click()
    Play.Stop
End Sub
Private Sub Command3_Click()
    On Error GoTo soo
    Dim snext As String
    last = last + 1
    snext = List1.List(last)
    List1.ListIndex = List1.ListIndex + 1
    Play.FileName = snext
    Play.Play
soo:
last = List1.ListIndex
 plays = ""
    Slider1.Max = Play.Duration
    Songname.Caption = List1.Text
End Sub

Private Sub Command4_Click()
Dim sfile As String
With Dialog
    .CancelError = False
    .Filter = "Mp3 Play list|*.mpl"
    .ShowOpen
    If .FileName = "" Then
    Exit Sub
    End If
    sfile = Dialog.FileName
    Dialog.FileName = ""
End With
    List1.Clear
Dim a As String
Dim X As String
On Error GoTo error
Open sfile For Input As #1
Do Until EOF(1)
Input #1, a$
List1.AddItem a$
Loop
Close 1
sfile = ""
Exit Sub
error:
X = MsgBox("File Not Found", vbOKOnly, "Error")

End Sub

Private Sub Command5_Click()
Me.WindowState = 1
End Sub


Private Sub Command6_Click()
    List1.Clear
End Sub

Private Sub Command7_Click()
    Image7_Click
End Sub

Private Sub Form_Load()
    plays = "stop"
    sloop = "False"
    Slider2.Value = 2500
    Dim sfile, a As String
    sfile = App.Path + "\" + "default.mpl"
    On Error GoTo serr
    Open sfile For Input As #1
    Do Until EOF(1)
    Input #1, a$
    List1.AddItem a$
    Loop
    Close #1
serr:
    Close #1
End Sub

Private Sub Form_Unload(Cancel As Integer)
Dim sfile As String
Dim i As Long
sfile = App.Path + "\" + "default.mpl"
On Error GoTo error
Open sfile For Output As #1
For i = 0 To 100
    List1.ListIndex = i
     Write #1, List1.Text
Next i
error:
    Close #1

End Sub

Private Sub Image7_Click()
   If frmmain.Height = 5715 Then
      frmmain.Height = 2085
   ElseIf frmmain.Height = 2085 Then
      frmmain.Height = 5715
   End If
End Sub

Private Sub Image8_Click()
frmAbout.Show vbModal
End Sub

Private Sub List1_DblClick()
    plays = "stop"
    Play.FileName = List1.Text
    Play.Play
    Slider1.Max = Play.Duration
    last = List1.ListIndex
    Songname.Caption = List1.Text
End Sub

Private Sub List1_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyDelete Then
        If List1.ListIndex = -1 Then
Else
    List1.RemoveItem List1.ListIndex
    End If
End If
End Sub

Private Sub mnumainclose_click()
End
End Sub

Private Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 2 Then
    Me.PopupMenu main
End If
End Sub

Private Sub Image1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = 1 Then
    FormDrag Me
    End If
End Sub

Private Sub open_Click()
Dim sfile As String
With Dialog
    .CancelError = False
    .Filter = "MP3 Files|*.mp3"
    .ShowOpen
End With
    If Dialog.FileName = "" Then
    Exit Sub
    ElseIf Not Right$(Dialog.FileName, 4) = ".mp3" Then
    Exit Sub
    End If
    sfile = Dialog.FileName
    Dialog.FileName = ""
Play.FileName = sfile
    List1.Clear
    List1.AddItem sfile
    Slider1.Max = Play.Duration
    sfile = ""
    List1.ListIndex = 0
    Songname.Caption = List1.Text
End Sub

Private Sub Pause_Click()
On Error Resume Next
  If Play.PlayState = 1 Then
    Play.Play
    Else
    Play.Pause
End If
End Sub

Private Sub Play_EndOfStream(ByVal Result As Long)
If Rep.BackColor = &HFF& Then
Exit Sub
Else: Play.Play
End If
End Sub

Private Sub Rem_Click()
    If List1.ListIndex = -1 Then
Else
    List1.RemoveItem List1.ListIndex
End If
End Sub

Private Sub Rep_Click()
    If Rep.BackColor = &HFF& Then
    Rep.BackColor = &HFF00&
    sloop = "True"
    ElseIf Rep.BackColor = &HFF00& Then
    Rep.BackColor = &HFF&
    sloop = "False"
    End If
End Sub

Private Sub Savelist_Click()
    Dim i As Long
    Dim sfile As String
With Dialog
    .CancelError = False
    .Filter = "Mp3 list|*.mpl"
    .ShowOpen
    If .FileName = "" Then
    Exit Sub
    End If
End With
    sfile = Dialog.FileName
    Dialog.FileName = ""
    On Error GoTo error
    Open sfile For Output As #1
For i = 0 To 100
    List1.ListIndex = i
     Write #1, List1.Text
Next i
error:
    Close #1
End Sub

Private Sub Slider1_Click()
        Play.CurrentPosition = Slider1.Value
End Sub

Private Sub Slider1_Scroll()
    Play.CurrentPosition = Slider1.Value
End Sub

Private Sub Slider2_Click()
    Play.Volume = Slider2.Value - 2500
End Sub

Private Sub Slider2_Scroll()
    Play.Volume = Slider2.Value - 2500
End Sub

Private Sub Timer1_Timer()
    Slider1.Value = Play.CurrentPosition
End Sub

Private Sub Timer2_Timer()
Dim tinseconden As Long
Dim lengths, lengths1, min, sec As Long
lengths = Play.Duration
tinseconden = Play.CurrentPosition
lengths1 = lengths - tinseconden
min = lengths1 \ 60
sec = lengths1 - min * 60
time.Caption = min & " : " & sec
End Sub
In order to use your player as default, do the following:

*Look for an MP3 file
*Right Click on it and select "open with"
*Select at the bottom "Choose program", a little window will pop up
*Press the browse button and look the ubication of your MP3 Player.
*When you find it, in the little window, click on the ckeckbox that says "run always with the selected program"
*Now you good to go

I hope this can help you
And it will really open with my program? sweet this looks very helpful
Quote Originally Posted by willrulz188 View Post
And it will really open with my program? sweet this looks very helpful
No it will not.
Quote Originally Posted by Jason View Post


No it will not.
well thats what I need
Look at changing file associations in the registry. You're bound to find good and descriptive examples on google. I know you didn't want that as a reference but seriously.

Let me google that for you

First few results look promising.

EDIT:
http://www.codeproject.com/KB/vb/VBFileAssociation.aspx

Very easy to follow and well described. Should be more than enough info for you to replicate.
What Jason means is SmartAlley solution will not, but File association will.

Read the link he provided, it will explain.
for replacing windows media player, you gotta replace the media player with your's, Make backups or wont work.

Rename your player to the windowsmediaplayer name, n add it to the folder, also dont forket to rename the first one, otherwise you'd be replacing it and it'd be gone forever.
Quote Originally Posted by o0OpurezO0o View Post
for replacing windows media player, you gotta replace the media player with your's, Make backups or wont work.

Rename your player to the windowsmediaplayer name, n add it to the folder, also dont forket to rename the first one, otherwise you'd be replacing it and it'd be gone forever.
Please read the thread before you post. It's entirely possible to change the default program with far less drastic measures. You think iTunes overwrites WMP when it gets set as the default program? No, it simply changes the file associations in the registry as I stated a few posts ago.
why dont you just use windows media player?
Quote Originally Posted by HalfBajan View Post
why dont you just use windows media player?
Because he wants to code his own media player? What a pointless post.
There is no good use for windows media player as a developer, other then avoiding coding your own player.
Posts 114 of 14 · Page 1 of 1
This thread is closed for replies.

Tags for this Thread

None

Need help?