Note:本篇開發端Media Player版本為11, WM6上Media版本為10.3
之前在"如何讓裝置發出聲音"這篇,我們有談過利用呼叫API的方式來播放wav檔,那如果要播放mp3那要怎麼做呢?
首先下面有一些參考資料
下面是測試的程式碼,可以參考看看
畫面上有一個ListBox名稱為ListBox1,兩個Button分別為btnStart、btnStop
- Public Class Form1
-
- Dim Player As WMPLib.WindowsMediaPlayer
-
- Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- For Each s As String In IO.Directory.GetFiles("\儲存卡\Music")
- ListBox1.Items.Add(s)
- Next
- Player = New WMPLib.WindowsMediaPlayer
- Player.settings.volume = 10
- End Sub
-
- Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
- If ListBox1.SelectedIndex >= 0 Then
- Player.URL = ListBox1.SelectedItem
- Player.controls.play()
- End If
- End Sub
-
- Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click
- Player.controls.stop()
- End Sub
- End Class