Mp3 Player(media Player)

Heres your chance to share your own tutorials with the community. Just post them on here. If your lucky they may even be posted on the main site.
8 posts Page 1 of 1
Contributors
User avatar
Toxikr3
Dedicated Member
Dedicated Member
Posts: 69
Joined: Tue Dec 08, 2009 12:49 am

Mp3 Player(media Player)
Toxikr3
Just thought I'd make a tutorial ^_^

Ok, let's start. I like to rename my objects, its easier to work with, so I will be using the renamed ... names =)

Required
1 Listbox
4 Buttons
1 Windows Media Player
1 Timer
1 Open File Dialog
1 Save File Dialog

The list box will hold your playlist so the media player can go through the songs.

Add all the objects on to your form.

Rename the listbox to "listurl" (without quotes)

Rename the 4 buttons to cmdPlay, cmdAddSong, cmdSave, cmdOpen

Rename Windows Media Player to WMP

Leave the dialogs and timer as is.


At the very top add this code
Code: Select all
Imports System.IO
Double click the cmdPlay button and add this
Code: Select all
on error goto manageerr
        If Listurl.SelectedIndex = -1 Then
            Listurl.SelectedIndex = 0
            WMP.URL = Listurl.SelectedItem
        End If

        If WMP.playState = WMPLib.WMPPlayState.wmppsPlaying Then
            WMP.Ctlcontrols.pause()
         Else
            WMP.Ctlcontrols.play()
        End If
exit sub
manageerr:
msgbox "An error has occured" & vbnewline & err.description

Double click Timer1 and add this
Code: Select all
On Error GoTo nosongs
        Dim nextSong As Integer
        Dim numberofSongs As Integer
        numberofSongs = Listurl.Items.Count
        If WMP.playState = WMPLib.WMPPlayState.wmppsStopped Then
            nextSong = Listurl.SelectedIndex + 1
            Listurl.SelectedItem = Listurl.Items.Item(Listurl.SelectedIndex + 1)
            WMP.URL = Listurl.SelectedItem
        End If
        Exit Sub
nosongs:
        WMP.URL = Listurl.Items.Item(0)
Double click cmdAddSongs and add this
Code: Select all
        OpenFileDialog1.ShowDialog()
        If OpenFileDialog1.CheckFileExists = True Then
            Listurl.Items.Add(OpenFileDialog1.FileName)
         End If
Double click cmdOpen and add this
Code: Select all
        Dim oresults As DialogResult
        oresults = OpenFileDialog1.ShowDialog()
        If oresults = Windows.Forms.DialogResult.OK Then

            Dim ioFile As New StreamReader(OpenFileDialog1.FileName)
            Dim ioLine As String ' Going to hold one line at a time
            Dim ioLines As String ' Going to hold whole file
            ioLine = ioFile.ReadLine
            Listurl.Items.Add(ioLine)
            ioLines = ioLine
            While Not ioLine = ""
                ioLine = ioFile.ReadLine
                ioLines = ioLines & vbCrLf & ioLine
                If ioLine <> "" Then
                    Listurl.Items.Add(ioLine)
                End If

             End While
            ioFile.Close()

        End If
Double click cmdSave and add this
Code: Select all
        Dim FileWriter As StreamWriter

        Dim results As DialogResult

        results = SaveFileDialog1.ShowDialog

        If results = DialogResult.OK Then

            FileWriter = New StreamWriter(SaveFileDialog1.FileName, False)

            For i = 0 To Listurl.Items.Count - 1
                FileWriter.Write(Listurl.Items.Item(i))
                FileWriter.Write(vbNewLine)
            Next i
            FileWriter.Close()

        End If
And thats it!
I have written all of this myself except the open and save code. I changed it a bit as you can see to write all the items in the list box.

I have cut some stuff out of this code to make it a bit simple, the one I am working on has a little bit more stuff. There might be some errors because of this, if there are just post and I'll help you.

You can of course take this code and make it a lot better. ^_^
Last edited by Toxikr3 on Thu Dec 31, 2009 1:45 am, edited 1 time in total.
User avatar
Nery
Co-Admin Moderator
Co-Admin Moderator
Posts: 1117
Joined: Mon Sep 07, 2009 8:11 pm

Re: Mp3 Player(media Player)
Nery
Good tutorial, I'm sure it'll help beginners (or even experts).
User avatar
tvs praveen
Top Poster
Top Poster
Posts: 205
Joined: Tue Dec 08, 2009 6:20 am

Re: Mp3 Player(media Player)
tvs praveen
Its not working, In the code of cmdPlay it says error in line
msgbox "An error has occured" & vbnewlinw & err.description

What should i do?
NoWayIn
VIP - Donator
VIP - Donator
Posts: 444
Joined: Sat Nov 21, 2009 11:16 pm

Re: Mp3 Player(media Player)
NoWayIn
tvs praveen wrote:
Its not working, In the code of cmdPlay it says error in line
msgbox "An error has occured" & vbnewlinw & err.description

What should i do?
A spelling mistake.

change vbnewlinw to vbnewline
User avatar
Toxikr3
Dedicated Member
Dedicated Member
Posts: 69
Joined: Tue Dec 08, 2009 12:49 am

Re: Mp3 Player(media Player)
Toxikr3
woops sorry for that ^_^
I was editing it while I was writing :P
NoWayIn
VIP - Donator
VIP - Donator
Posts: 444
Joined: Sat Nov 21, 2009 11:16 pm

Re: Mp3 Player(media Player)
NoWayIn
It's a simple mistake, hehe
User avatar
Usman55
VIP - Site Partner
VIP - Site Partner
Posts: 2821
Joined: Thu Dec 24, 2009 7:52 pm

Re: Mp3 Player(media Player)
Usman55
It's just amazing!
Image
User avatar
tvs praveen
Top Poster
Top Poster
Posts: 205
Joined: Tue Dec 08, 2009 6:20 am

Re: Mp3 Player(media Player)
tvs praveen
NoWayIn wrote:
tvs praveen wrote:
Its not working, In the code of cmdPlay it says error in line
msgbox "An error has occured" & vbnewlinw & err.description

What should i do?
A spelling mistake.

change vbnewlinw to vbnewline

Thanks NowWayIn!
8 posts Page 1 of 1
Return to “Tutorials”