在vb.net2010里做一个音乐播放器,昨晚发现添加在listbox里的歌曲不能播放。求大神指教
这是代码PublicClassForm1Dimab,a,bAsStringDimiPrivateSubButton1_Click(ByValsenderAsSystem....
这是代码
Public Class Form1
Dim ab, a, b As String
Dim i
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim song As String
With OpenFileDialog1
.Filter = "(*.mp3)|*.mp3"
.ShowDialog()
song = .FileName
End With
If song = "" Then Exit Sub
a = ""
For i = Len(song) To 1 Step -1
b = Mid(song, i, 1)
If b = "" Then
Me.ListBox1.Items.Add(a)
a = ""
ElseIf b = "\" Then
Me.ListBox1.Items.Add(a)
ab = Microsoft.VisualBasic.Left(song, i)
Exit Sub
Else
a = b & a
End If
Next i
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Me.AxWindowsMediaPlayer1.URL = ab & Me.ListBox1.Text
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim song As String
If FolderBrowserDialog1.ShowDialog() <> DialogResult.Cancel Then
Me.ListBox1.Text = FolderBrowserDialog1.SelectedPath
' Me.ListBox1.SelectionStart = Me.ListBox1.Text.Length
Dim FileNames() As String = Directory.GetFiles(Me.ListBox1.Text)
For i As Integer = 0 To FileNames.Length - 1
ListBox1.Items.Add(Path.GetFileName(FileNames(i)))
Next
End If
If song = "" Then Exit Sub
a = ""
For i = Len(song) To 1 Step -1
b = Mid(song, i, 1)
If b = "" Then
Me.ListBox1.Items.Add(a)
a = ""
ElseIf b = "\" Then
Me.ListBox1.Items.Add(a)
ab = Microsoft.VisualBasic.Left(song, i)
Exit Sub
Else
a = b & a
End If
Next i
End Sub
End Class 展开
Public Class Form1
Dim ab, a, b As String
Dim i
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim song As String
With OpenFileDialog1
.Filter = "(*.mp3)|*.mp3"
.ShowDialog()
song = .FileName
End With
If song = "" Then Exit Sub
a = ""
For i = Len(song) To 1 Step -1
b = Mid(song, i, 1)
If b = "" Then
Me.ListBox1.Items.Add(a)
a = ""
ElseIf b = "\" Then
Me.ListBox1.Items.Add(a)
ab = Microsoft.VisualBasic.Left(song, i)
Exit Sub
Else
a = b & a
End If
Next i
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Me.AxWindowsMediaPlayer1.URL = ab & Me.ListBox1.Text
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim song As String
If FolderBrowserDialog1.ShowDialog() <> DialogResult.Cancel Then
Me.ListBox1.Text = FolderBrowserDialog1.SelectedPath
' Me.ListBox1.SelectionStart = Me.ListBox1.Text.Length
Dim FileNames() As String = Directory.GetFiles(Me.ListBox1.Text)
For i As Integer = 0 To FileNames.Length - 1
ListBox1.Items.Add(Path.GetFileName(FileNames(i)))
Next
End If
If song = "" Then Exit Sub
a = ""
For i = Len(song) To 1 Step -1
b = Mid(song, i, 1)
If b = "" Then
Me.ListBox1.Items.Add(a)
a = ""
ElseIf b = "\" Then
Me.ListBox1.Items.Add(a)
ab = Microsoft.VisualBasic.Left(song, i)
Exit Sub
Else
a = b & a
End If
Next i
End Sub
End Class 展开
展开全部
ab & Me.ListBox1.Text
你确定歌曲文件名和扩展名是listbox的text属性,而不是其列表集合listbox1.items?
me.listbox1.text的赋值应该是你的button2,那是一个目录名,ab也是目录名,这句等于是两个目录名拼接。
得到目录名,这句就够了。
ab = IO.Path.GetDirectoryName(song) & "\"
你确定歌曲文件名和扩展名是listbox的text属性,而不是其列表集合listbox1.items?
me.listbox1.text的赋值应该是你的button2,那是一个目录名,ab也是目录名,这句等于是两个目录名拼接。
得到目录名,这句就够了。
ab = IO.Path.GetDirectoryName(song) & "\"
追问
还是不行啊。
追答
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim song As String
With OpenFileDialog1
.Filter = "(*.mp3)|*.mp3"
.ShowDialog()
song = .FileName
End With
ListBox1.Text = IO.Path.GetDirectoryName(song)
ListBox1.Items.Add(IO.Path.GetFileName(song))
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
……
For i As Integer = 0 To FileNames.Length - 1
ListBox1.Items.Add(Path.GetFileName(FileNames(i)))
Next
End If
''''后面的代码都可以删了
end sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Me.AxWindowsMediaPlayer1.URL = Me.ListBox1.Text & "\" & ListBox1.SelectedItem.ToString()
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询