Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Integer, ByVal hwndCallback As Integer) As Integer Private Declare Function mciExecute Lib "winmm.dll" (ByVal IpstrCommand As String) As Integer '■再生 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim FileName As String = "C:\Test\Test.mp3" Call mciSendString(String.Format("open ""{0}"" alias MySound", FileName), "", 0, 0) Call mciExecute("set MySound speed 2000 ") Call mciSendString("play MySound", "", 0, 0) End Sub '■再生終了(完全停止) Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Call mciSendString("stop MySound", "", 0, 0) Call mciSendString("close MySound", "", 0, 0) End Sub
Public Class Form1 Dim sound As Sound '■再生 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click sound = New Sound("C:\Test\Test.mp3") sound.Speed = 2000 sound.Play() End Sub '■再生終了(完全停止) Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click sound.Stop() End Sub End Class Public Class Sound Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Integer, ByVal hwndCallback As Integer) As Integer Private Declare Function mciExecute Lib "winmm.dll" (ByVal IpstrCommand As String) As Integer Public Sub New(ByVal fileName As String) Me.FileName = fileName End Sub Public Overridable Sub Play() Call mciSendString(String.Format("open ""{0}"" alias MySound", FileName), "", 0, 0) Call mciExecute("set MySound speed " & Me.Speed) Call mciSendString("play MySound", "", 0, 0) End Sub Public Overridable Sub [Stop]() Call mciSendString("stop MySound", "", 0, 0) Call mciSendString("close MySound", "", 0, 0) End Sub Private _FileName As String Public Overridable Property FileName As String Get Return _FileName End Get Set(ByVal value As String) _FileName = value End Set End Property Private _Speed As Integer = 1000 Public Overridable Property Speed As Integer Get Return _Speed End Get Set(ByVal value As Integer) _Speed = value End Set End Property End Class