VB.NET Programming
[VBNET] [API] mciSendString - WAV 파일 재생
ZerosKD
2020. 4. 21. 13:18
반응형
*VBNET API 를 이용한 Wav 파일 재생 예제...
- 사용한 컨트롤 : Button 3개, Label 1개
전체 소스 코드
Form1.vb
Imports System.Runtime.InteropServices
Imports System.Text
Public Class Form1
<DllImport("winmm.dll")> _
Private Shared Function mciSendString(ByVal command As String, ByVal buffer As StringBuilder, ByVal bufferSize As Integer, ByVal hwndCallback As IntPtr) As Integer
End Function
Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
'File Open
Dim ofd As OpenFileDialog = New OpenFileDialog
ofd.Filter = "WAV File(*.wav) | *.wav"
If ofd.ShowDialog() = Windows.Forms.DialogResult.OK Then
label1.Text = ofd.FileName
End If
End Sub
Private Sub button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button2.Click
'Play
If Not System.IO.File.Exists(label1.Text) Then
Return
End If
mciSendString("open """ + label1.Text + """ type mpegvideo alias MediaFile", Nothing, 0, IntPtr.Zero)
mciSendString("play MediaFile", Nothing, 0, IntPtr.Zero)
End Sub
Private Sub button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button3.Click
'Stop
mciSendString("Close MediaFile", Nothing, 0, IntPtr.Zero)
End Sub
End Class
*예제 결과
https://kdsoft-zeros.tistory.com/192
반응형