1.你使用的媒体控制是什么?
成都创新互联是一家专注于网站建设、做网站与策划设计,赫章网站建设哪家好?成都创新互联做网站,专注于网站建设10年,网设计领域的专业建站公司;建站业务涵盖:赫章等地区。赫章做网站价格咨询:13518219792
2.要加入ListBox的双击事件
3. 你这里只是用浏览对话框找到了mp3文件,并显示在列表框里。没有播放的代码。
张志晨
add
...............................................
添加WMplayer控件
Public Class Form1
Private Sub 打开目录ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 打开目录ToolStripMenuItem.Click
If FolderBrowserDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim f As IO.FileInfo
Dim d As IO.DirectoryInfo = New IO.DirectoryInfo(FolderBrowserDialog1.SelectedPath)
Dim file As String
For Each f In d.GetFiles("*.mp3")
file = (f.FullName)
ListBox1.Items.Add(file)
Next
End If
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged‘双击就播放
AxWindowsMediaPlayer1.URL = ListBox1.Items(ListBox1.SelectedIndex)
End Sub
End Class
方法只是添加一个播放器控件,再改它的属性就可以了.
添加播放器控件的方法:在窗体设计模式中,右键单击”工具箱”->”WINDOWS 窗体”,选择”添加/移除项”,再选择”COM组件”标签找到”WINDOWS MEDIA PLAYER”项,选上.最后把添加了控件放到窗体中就行了.
我没有ATI格式的文件也不知道MEDIA PLAYER能放不,不行的话用别的控件试试,比如REALPLAYER.
邮件我已经发过去了.
我这里有一段前段时间写的测试代码,使用WMPLib类,中间有你需要的功能,你可以参考下:
使用wmp.currentMedia.duration和wmp.currentMedia.durationString分别以double和string获得当前媒体的播放时间,使用wmp.settings.volume设置音量大小,使用wmp.controls.currentPosition设置当前播放时间点
Imports WMPLib
Public Class FrmMain
Dim WithEvents wmp As WMPLib.WindowsMediaPlayer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
wmp = New WMPLib.WindowsMediaPlayer()
TextBox1.Text = TextBox1.Text vbCrLf "当前播放状态:" wmp.status
wmp.uiMode = "Mini"
wmp.settings.balance = 1
wmp.enableContextMenu = True
wmp.fullScreen = False
wmp.windowlessVideo = True
wmp.enabled = True
Dim wmpMediaList As IWMPPlaylist = wmp.newPlaylist("默认播放列表", "")
Dim wmpMedia As IWMPMedia = wmp.newMedia(My.Computer.FileSystem.CurrentDirectory "\Human.mp3")
With wmpMediaList
.appendItem(wmpMedia)
End With
'wmp.URL = "\\192.168.1.247\sharoncn\music\Human.mp3"
wmp.currentMedia = wmpMedia
wmp.settings.autoStart = True
tBarPlay.Value = 0
ListBox1.Items.Add(wmpMediaList.name)
ListBox1.SelectedIndex = 0
ListBox2.Items.Add(wmpMediaList.Item(0).name)
ListBox2.SelectedIndex = 0
tbar.Maximum = 100
tbar.Value = 50
Timer1.Enabled = True
Timer1.Interval = 100
End Sub
Private Sub wmp_PlayStateChange(ByVal NewState As Integer) Handles wmp.PlayStateChange
tBarPlay.Maximum = wmp.currentMedia.duration * 10
Label1.Text = "总时间:" wmp.currentMedia.durationString
TextBox1.Text = TextBox1.Text vbCrLf "当前播放状态:" NewState
If NewState = 1 Then
wmp.controls.play()
End If
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
TextBox1.SelectionStart = Len(TextBox1.Text)
TextBox1.ScrollToCaret()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Label2.Text = "当前播放进度:" wmp.controls.currentPositionString
tBarPlay.Value = CInt(wmp.controls.currentPosition * 10)
End Sub
Private Sub tbar_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tbar.Scroll
wmp.settings.volume = tbar.Value
End Sub
Private Sub tBarPlay_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tBarPlay.Scroll
wmp.controls.currentPosition = tBarPlay.Value / 10
End Sub
End Class
你去看过书吗?其实这个不会很难的。特别是那个界面很容易的。自己去研究下先了。不懂再问高手们了