當前位置:編程學習大全網 - 編程語言 - 關於MP3編程

關於MP3編程

Imports System.IO

Public Class frmPlayer

Dim playlist(10000) As String

Dim NoOfMusic As Integer

Private Sub AddFile(ByVal path As String)

If NoOfMusic < 10000 Then

NoOfMusic = NoOfMusic + 1

playlist(NoOfMusic) = path

End If

End Sub

Private Sub DelFile(ByVal SelectNum As String)

Dim i As Integer

For i = SelectNum To NoOfMusic - 1

playlist(i) = playlist(i + 1)

Next

End Sub

Private Sub Play(ByVal SelectNum As Integer)

MediaPlayer.URL = playlist(SelectNum)

End Sub

Private Sub Addfiles(ByVal path As String, ByVal listb As ListBox)

Dim dir As DirectoryInfo = New DirectoryInfo(path)

Dim f As FileInfo

For Each f In dir.GetFiles("*.wmv")

AddFile(f.FullName)

Dim i As Integer

Dim strfile As String = Convert.ToString(NoOfMusic)

For i = 1 To i <= 5 - strfile.Length

strfile = strfile + ""

Next i

strfile = strfile + "- -" + f.Name

ListBox.Items.Add(strfile)

Next f

Dim d As DirectoryInfo

For Each d In dir.GetDirectories()

addfiles(d.FullName, ListBox)

Next

End Sub

Private Sub btnPlay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlay.Click

Dim SelectOne As Integer

If ListBox.SelectedIndex < 0 Then

SelectOne = 1

Else

SelectOne = ListBox.SelectedIndex + 1

End If

If ListBox.Items.Count < 0 Then

ListBox.SelectedIndex = 0

End If

play(SelectOne)

End Sub

Private Sub btnAddSong_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddSong.Click

Dim i As Integer

If OFDialog.ShowDialog = Windows.Forms.DialogResult.OK Then

Dim path As String = OFDialog.FileName

Dim f As FileInfo = New FileInfo(path)

AddFile(f.FullName)

Dim strfile As String = Convert.ToString(NoOfMusic)

For i = 1 To i <= 5 - strfile.Length

strfile = strfile + ""

Next i

strfile = strfile + "- -" + f.Name

ListBox.Items.Add(strfile)

End If

End Sub

Private Sub btnAddDir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddDir.Click

On Error GoTo ErrHandler

FBDialog.SelectedPath = "C:\"

FBDialog.ShowNewFolderButton = True

FBDialog.Description = "請選擇文件夾目錄"

FBDialog.ShowDialog()

'Text = FBDialog.SelectedPath

Addfiles(FBDialog.SelectedPath, ListBox)

Exit Sub

ErrHandler:

Exit Sub

End Sub

Private Sub btnDel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDel.Click

If ListBox.SelectedIndex > 0 Then

DelFile(ListBox.SelectedIndex + 1)

ListBox.Items.Remove(ListBox.SelectedIndex)

End If

End Sub

Private Sub btnLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLast.Click

If ListBox.SelectedIndex >= 0 Then

ListBox.SelectedIndex = ListBox.SelectedIndex - 1

ElseIf ListBox.SelectedIndex = NoOfMusic - 1 Then

ListBox.SelectedIndex = NoOfMusic - 1

Play(ListBox.SelectedIndex + 1)

End If

End Sub

Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click

If ListBox.SelectedIndex < ListBox.Items.Count - 1 Then

ListBox.SelectedIndex = ListBox.SelectedIndex + 1

Else

If ListBox.Items.Count > 0 Then

ListBox.SelectedIndex = 0

End If

End If

Play(ListBox.SelectedIndex + 1)

End Sub

Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click

MediaPlayer.URL = ""

End Sub

Private Sub frmPlayer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

ListBox.Items.CopyTo(playlist, 0)

NoOfMusic = 0

End Sub

End Class

  • 上一篇:潮州出現過什麽偉大的歷史名人?
  • 下一篇:小學數學公開課活動總結
  • copyright 2024編程學習大全網