我這里有一段前段時(shí)間寫的測試代碼,使用WMPLib類,中間有你需要的功能,你可以參考下:
創(chuàng)新互聯(lián)專注于企業(yè)成都全網(wǎng)營銷推廣、網(wǎng)站重做改版、驛城網(wǎng)站定制設(shè)計(jì)、自適應(yīng)品牌網(wǎng)站建設(shè)、H5開發(fā)、購物商城網(wǎng)站建設(shè)、集團(tuán)公司官網(wǎng)建設(shè)、成都外貿(mào)網(wǎng)站制作、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁設(shè)計(jì)等建站業(yè)務(wù),價(jià)格優(yōu)惠性價(jià)比高,為驛城等各大城市提供網(wǎng)站開發(fā)制作服務(wù)。
使用wmp.currentMedia.duration和wmp.currentMedia.durationString分別以double和string獲得當(dāng)前媒體的播放時(shí)間,使用wmp.settings.volume設(shè)置音量大小,使用wmp.controls.currentPosition設(shè)置當(dāng)前播放時(shí)間點(diǎn)
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 "當(dāng)前播放狀態(tài):" 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("默認(rèn)播放列表", "")
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 = "總時(shí)間:" wmp.currentMedia.durationString
TextBox1.Text = TextBox1.Text vbCrLf "當(dāng)前播放狀態(tài):" 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 = "當(dāng)前播放進(jìn)度:" 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
控件使用是小問題,問題是你有沒有流媒體的通訊傳輸設(shè)備,有就可以了!設(shè)備傳文件過來的的時(shí)候就像使用一般多媒體文件一樣,找到它就可以了!關(guān)鍵是流媒體轉(zhuǎn)換設(shè)備??!
1.你使用的媒體控制是什么?
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
方法只是添加一個(gè)播放器控件,再改它的屬性就可以了.
添加播放器控件的方法:在窗體設(shè)計(jì)模式中,右鍵單擊”工具箱”->”WINDOWS 窗體”,選擇”添加/移除項(xiàng)”,再選擇”COM組件”標(biāo)簽找到”WINDOWS MEDIA PLAYER”項(xiàng),選上.最后把添加了控件放到窗體中就行了.
我沒有ATI格式的文件也不知道MEDIA PLAYER能放不,不行的話用別的控件試試,比如REALPLAYER.
郵件我已經(jīng)發(fā)過去了.