Imports System.Runtime.InteropServices Imports System.Text Imports System.IO Public Class Form1 <DllImport("winmm.dll", CharSet:=CharSet.Auto)> _ Private Shared Function mciSendString( _ ByVal command As String, _ ByVal buffer As StringBuilder, _ ByVal bufferSize As Integer, _ ByVal hwndCallback As IntPtr) As Integer End Function Dim FileName As String Private Sub Mp3形式ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Mp3形式ToolStripMenuItem.Click Me.OpenFileDialog1.Filter = "MP3形式サウンド(*.mp3)|*.mp3" Me.OpenFileDialog1.InitialDirectory = Application.StartupPath If Me.OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then FileName = Me.OpenFileDialog1.FileName Me.ListBox1.Text = Path.GetFileName(FileName) End If End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If File.Exists(FileName) Then Dim Command As String Command = String.Format("open ""{0}"" alias {1}", FileName, "MySound") mciSendString(Command, Nothing, 0, IntPtr.Zero) Command = String.Format("status {0} {1}", "MySound", "length") Dim Res As New StringBuilder(256) mciSendString(Command, Res, Res.Capacity, IntPtr.Zero) HScrollBar1.Maximum = Integer.Parse(Res.ToString) Command = "play MySound" mciSendString(Command, Nothing, 0, IntPtr.Zero) Me.Timer1.Interval = 500 Me.Timer1.Start() End If End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Timer1.Stop() Dim Command As String Command = String.Format("stop {0}", "MySound") mciSendString(Command, Nothing, 0, IntPtr.Zero) Command = String.Format("close {0}", "MySound") mciSendString(Command, Nothing, 0, IntPtr.Zero) End Sub Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick Dim Command As String = String.Format("status {0} {1}", "MySound", "position") Dim Res As New StringBuilder(256) mciSendString(Command, Res, Res.Capacity, IntPtr.Zero) Me.HScrollBar1.Value = Integer.Parse(Res.ToString) End Sub Private Sub HScrollBar1_Scroll(ByVal sender As Object, ByVal e As System.EventArgs) Handles HScrollBar1.Scroll Dim HScrollBar1 As HScrollBar = DirectCast(sender, HScrollBar) Dim Command As String Command = String.Format("seek {0} to {1}", "MySound", HScrollBar1.Value) mciSendString(Command, Nothing, 0, IntPtr.Zero) Command = String.Format("play {0}", "MySound") mciSendString(Command, Nothing, 0, IntPtr.Zero) End Sub