VB.NET-Quellcode
- Public Class Form1
- Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpszCommand As String, ByVal lpszReturnString As String, ByVal cchReturnLength As Integer, ByVal hwndCallback As Integer) As Integer
- Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Integer) As Integer
- #Region " MP3-Datei abspielen "
- Public Function MP3_Play(ByVal sFile As String, _
- ByVal sAlias As String) As Boolean
- Dim bResult As Boolean
- Dim sBuffer As String
- Dim lResult As Long
- sBuffer = Space$(255)
- lResult = GetShortPathName(sFile, sBuffer, Len(sBuffer))
- If lResult <> 0 Then
- sFile = Microsoft.VisualBasic.Left(sBuffer, InStr(sBuffer, vbNullChar) - 1)
- ' MCI öffnen
- lResult = mciSendString("open " & sFile & _
- " type MPEGVideo alias " & sAlias, 0, 0, 0)
- If lResult = 0 Then
- ' MP3 abspielen
- If mciSendString("play " & sAlias & _
- " from 0", 0, 0, 0) = 0 Then
- bResult = True
- End If
- End If
- End If
- MP3_Play = bResult
- End Function
- #End Region
- #Region " Wiedergabe stoppen und MCI schließen "
- Private Sub MP3_Stop(ByVal sAlias As String)
- mciSendString("stop " & sAlias, 0, 0, 0)
- mciSendString("close " & sAlias, 0, 0, 0)
- End Sub
- #End Region
- Private Sub cmdPlay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPlay.Click
- OpenDialog.DefaultExt = "mp3"
- OpenDialog.ShowDialog()
- TextBox_mp3.Text = OpenDialog.FileName
- MP3_Play(TextBox_mp3.Text, "MyAlias")
- End Sub
- Private Sub cmdPause_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPause.Click
- mciSendString("pause " + TextBox_mp3.Text, 0, 0, 0)
- End Sub
- Private Sub cmdStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdStop.Click
- MP3_Stop("MyAlias")
- End Sub
- End Class
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „Agent“ ()