Visual basic 2008 Music Player
- poruka: 7
- |
- čitano: 1.692
- |
- moderatori:
Lazarus Long, XXX-Man, vincimus
- +/- sve poruke
- ravni prikaz
- starije poruke gore
Napravio sam sebi mali music player i ocu da npr uzmem neku pjesmu i nanesem je na moj musix player i da ona pocne pjevat kako sad to uradit evo slik
Napisi kod i sto si koristio za taj music player..
provlem je u tome sro neznam kodove a koristio sam windows media player controls
provlem je u tome sro neznam kodove a koristio sam windows media player controls
Sto si pisao u VB?
Public Class Form1
Private IsFormBeingDragged As Boolean = False
Private MouseDownX As Integer
Private MouseDownY As Integer
Private PlayAgain As Boolean
Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Me.Close()
End Sub
Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
End Sub
Private Sub PictureBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox2.Click
End Sub
Private Sub PictureBox2_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox2.MouseMove
If e.Button = Windows.Forms.MouseButtons.Left Then
Me.Size = New Size(Me.PointToClient(MousePosition).X, Me.PointToClient(MousePosition).Y)
End If
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
My.Settings.mp3 = TextBox1.Text
My.Settings.Save()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TextBox1.Text = My.Settings.mp3
Width = 100
Height = 194
Label1.Width = 295
Label1.Height = 24
TrackBar1.Value = AxWindowsMediaPlayer1.settings.volume
End Sub
Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
End Sub
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
End Sub
Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
End Sub
Private Sub PictureBox3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Me.Hide()
Me.Refresh()
End Sub
Private Sub PictureBox1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs)
Me.Close()
End Sub
Private Sub PictureBox1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs)
Me.Refresh()
End Sub
Private Sub PictureBox1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs)
End Sub
Private Sub PictureBox3_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs)
PictureBox2.Hide()
Me.Refresh()
End Sub
Private Sub PictureBox1_Click_2(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
Me.Close()
End Sub
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
End Sub
Private Sub Label1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseDown
If e.Button = MouseButtons.Left Then
IsFormBeingDragged = True
MouseDownX = e.X
MouseDownY = e.Y
End If
End Sub
Private Sub Label1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseMove
If IsFormBeingDragged Then
Dim temp As Point = New Point()
temp.X = Me.Location.X + (e.X - MouseDownX)
temp.Y = Me.Location.Y + (e.Y - MouseDownY)
Me.Location = temp
temp = Nothing
End If
End Sub
Private Sub Label1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseUp
If e.Button = MouseButtons.Left Then
IsFormBeingDragged = False
End If
End Sub
Private Sub NotifyIcon1_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseDoubleClick
Me.Show()
End Sub
Private Sub HideToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HideToolStripMenuItem.Click
Me.Hide()
End Sub
Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
Me.Close()
End Sub
Private Sub PictureBox4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox4.Click
AxWindowsMediaPlayer1.Ctlcontrols.play()
TextBox1.Text = ListBox1.SelectedItem
AxWindowsMediaPlayer1.URL = ListBox1.SelectedItem
Label3.Text = TextBox1.Text
PlaySong()
TextBox1.Text = ListBox1.SelectedItem
End Sub
Private Sub PictureBox7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox7.Click
Timer1.Stop()
Me.Refresh()
AxWindowsMediaPlayer1.Ctlcontrols.pause()
Me.Refresh()
End Sub
Private Sub PictureBox8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
AxWindowsMediaPlayer1.Ctlcontrols.stop()
End Sub
Private Sub PictureBox4_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox4.MouseEnter
End Sub
Private Sub PictureBox9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub PictureBox9_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs)
End Sub
Private Sub PictureBox9_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs)
End Sub
Private Sub PictureBox7_MouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox7.MouseDoubleClick
AxWindowsMediaPlayer1.Ctlcontrols.play()
End Sub
Private Sub PictureBox7_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox7.MouseEnter
End Sub
Private Sub PictureBox10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub PictureBox10_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Height = 194
Me.Width = 600
Label1.Width = 480
End Sub
Private Sub PictureBox9_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox9.Click
Me.Height = 194
Me.Width = 400
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
OpenFileDialog1.ShowDialog()
AxWindowsMediaPlayer1.URL = OpenFileDialog1.FileName
TextBox1.Text = System.IO.Path.GetFileName(ListBox2.SelectedItem)
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
End Sub
Private Sub PictureBox6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox6.Click
Try
ListBox1.SelectedIndex += -1
ListBox2.SelectedIndex += -1
AxWindowsMediaPlayer1.URL = ListBox1.SelectedItem
TextBox1.Text = System.IO.Path.GetFileName(ListBox1.SelectedItem)
Catch ex As Exception
MsgBox("No song")
End Try
Label3.Text = TextBox1.Text
PlaySong()
End Sub
Private Sub PictureBox5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox5.Click
Try
ListBox1.SelectedIndex += +1
ListBox2.SelectedIndex += +1
AxWindowsMediaPlayer1.URL = ListBox1.SelectedItem
TextBox1.Text = System.IO.Path.GetFileName(ListBox1.SelectedItem)
ListBox2.Text = (ListBox1.SelectedItem)
Catch ex As Exception
MsgBox("No song")
End Try
Label3.Text = TextBox1.Text
PlaySong()
End Sub
Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
For Each track In OpenFileDialog1.FileNames
ListBox2.Items.Add(System.IO.Path.GetFileName(track))
Next
For Each track In OpenFileDialog1.FileNames
ListBox1.Items.Add(track)
Next
ListBox2.SelectedIndex = 1
ListBox1.SelectedIndex = 1
TextBox1.Text = System.IO.Path.GetFileName(ListBox1.SelectedItem)
End Sub
Private Sub ListBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick
AxWindowsMediaPlayer1.Ctlcontrols.play()
End Sub
Private Sub ListBox1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseClick
AxWindowsMediaPlayer1.Ctlcontrols.play()
AxWindowsMediaPlayer1.Ctlcontrols.play()
TextBox1.Text = ListBox2.SelectedItem
AxWindowsMediaPlayer1.URL = ListBox1.SelectedItem
Label3.Text = TextBox1.Text
ListBox1.SelectedItem = ListBox2.SelectedItem
Me.Refresh()
End Sub
Private Sub ListBox1_SelectedIndexChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
End Sub
Private Sub AxSlider1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub ListBox2_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles ListBox2.DragDrop
End Sub
Private Sub ListBox2_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox2.MouseClick
ListBox1.SelectedIndex = ListBox2.SelectedIndex
AxWindowsMediaPlayer1.Ctlcontrols.play()
TextBox1.Text = ListBox2.SelectedItem
AxWindowsMediaPlayer1.URL = ListBox1.SelectedItem
Label3.Text = TextBox1.Text
PlaySong()
End Sub
Private Sub ListBox2_MouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox2.MouseDoubleClick
AxWindowsMediaPlayer1.Ctlcontrols.play()
End Sub
Private Sub ListBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox2.SelectedIndexChanged
End Sub
Private Sub ProgressBar1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
AxWindowsMediaPlayer1.Ctlcontrols.play()
End Sub
Private Sub PictureBox8_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox8.Click
AxWindowsMediaPlayer1.Ctlcontrols.stop()
StopSong()
End Sub
Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs)
AxWindowsMediaPlayer1.settings.volume = TrackBar1.Value
End Sub
Private Sub TrackBar1_Scroll_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll
AxWindowsMediaPlayer1.settings.volume = TrackBar1.Value
Label2.Text = TrackBar1.Value * 1
End Sub
Private Sub Label3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub AxWindowsMediaPlayer1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AxWindowsMediaPlayer1.Enter
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Label3.Left -= 5
If Label3.Left <= -Width Then
Label3.Left = Width
End If
End Sub
Private Sub Label3_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label3.Click
End Sub
Private Sub Label3_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Label3.MouseEnter
Timer1.Start()
End Sub
Private Sub Label3_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Label3.MouseLeave
Timer1.Stop()
Label3.Location = New Point(15, 154)
End Sub
Private Sub PlayBar_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles PlayBar.Scroll
Try
If (AxWindowsMediaPlayer1.currentMedia.duration <> 0) Then
Dim NewPerc As Double = Convert.ToDouble(PlayBar.Value) / 100
Dim DurationVar As Integer = Convert.ToInt32(AxWindowsMediaPlayer1.currentMedia.duration * 1000) ' milliseconds
Dim NewPos As Integer = (DurationVar * NewPerc) / 1000
AxWindowsMediaPlayer1.Ctlcontrols.currentPosition = NewPos
Else
PlayBar.Value = 0
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub PlaySong()
If AxWindowsMediaPlayer1.URL <> "" Then
AxWindowsMediaPlayer1.Ctlcontrols.play()
DurationTimer.Enabled = True
Else
DurationTimer.Enabled = False
End If
End Sub
Private Sub PauseSong()
AxWindowsMediaPlayer1.Ctlcontrols.pause()
End Sub
Private Sub StopSong()
AxWindowsMediaPlayer1.Ctlcontrols.stop()
Duration.Text = "00:00"
DurationTimer.Enabled = False
PlayBar.Value = 0
End Sub
Private Sub DurationTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DurationTimer.Tick
' Update the trackbar.
Dim CurPos As Integer = Convert.ToInt32(AxWindowsMediaPlayer1.Ctlcontrols.currentPosition * 1000) ' milliseconds
Dim DurationVar As Integer = Convert.ToInt32(AxWindowsMediaPlayer1.currentMedia.duration * 1000) ' milliseconds
If DurationVar > 0 Then
PlayBar.Value = Convert.ToInt32((CurPos * 100) / DurationVar) ' % complete
End If
' Update the time label
Duration.Text = AxWindowsMediaPlayer1.Ctlcontrols.currentPositionString
If AxWindowsMediaPlayer1.playState = WMPLib.WMPPlayState.wmppsStopped Then
Duration.Text = "00:00"
DurationTimer.Enabled = False
PlayBar.Value = 0
End If
If PlayAgain = False Then
Else
If AxWindowsMediaPlayer1.playState = WMPLib.WMPPlayState.wmppsStopped Then
PlaySong()
Else
End If
End If
End Sub
Private Sub PictureBox9_MouseEnter1(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox9.MouseEnter
End Sub
Private Sub PictureBox9_MouseLeave1(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox9.MouseLeave
End Sub
Private Sub PictureBox10_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub PictureBox10_MouseLeave1(ByVal sender As Object, ByVal e As System.EventArgs)
End Sub
Private Sub PictureBox6_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox6.MouseEnter
End Sub
Private Sub PictureBox11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub PictureBox11_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs)
End Sub
Private Sub PictureBox5_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox5.MouseEnter
End Sub
Private Sub PictureBox12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub PictureBox12_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs)
End Sub
Private Sub PictureBox13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub PictureBox13_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs)
End Sub
Private Sub PictureBox14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub PictureBox14_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs)
End Sub
End Class
Jesi probao samo povuc na listu? Jer vidim da ti tamo ima drag'ndrop na listu br 2.
Hvala Ivo, na pastebin je puno urednije.
I kad programiras nesto, promjeni nazive komponenti da se lakse raspozna kasnije, jer kad trazis bugove u kodu se lako izgubis ako nije oznaceno.