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
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
Double click Timer1 and add this
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. ^_^
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
Double click the cmdPlay button and add this
Imports System.IO
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
Double click cmdAddSongs and add this
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)
Code: Select all
Double click cmdOpen and add this
OpenFileDialog1.ShowDialog()
If OpenFileDialog1.CheckFileExists = True Then
Listurl.Items.Add(OpenFileDialog1.FileName)
End If
Code: Select all
Double click cmdSave and add this
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
Code: Select all
And thats it! 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
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.
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?
msgbox "An error has occured" & vbnewlinw & err.description
What should i do?
tvs praveen wrote:Its not working, In the code of cmdPlay it says error in lineA spelling mistake.
msgbox "An error has occured" & vbnewlinw & err.description
What should i do?
change vbnewlinw to vbnewline
woops sorry for that ^_^
I was editing it while I was writing :P
I was editing it while I was writing :P
NoWayIn wrote:tvs praveen wrote:Its not working, In the code of cmdPlay it says error in lineA spelling mistake.
msgbox "An error has occured" & vbnewlinw & err.description
What should i do?
change vbnewlinw to vbnewline
Thanks NowWayIn!
8 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023