MP3 abspielen

    • VB.NET

      MP3 abspielen

      VB.NET-Quellcode

      1. Public Class Form1
      2. 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
      3. Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Integer) As Integer
      4. #Region " MP3-Datei abspielen "
      5. Public Function MP3_Play(ByVal sFile As String, _
      6. ByVal sAlias As String) As Boolean
      7. Dim bResult As Boolean
      8. Dim sBuffer As String
      9. Dim lResult As Long
      10. sBuffer = Space$(255)
      11. lResult = GetShortPathName(sFile, sBuffer, Len(sBuffer))
      12. If lResult <> 0 Then
      13. sFile = Microsoft.VisualBasic.Left(sBuffer, InStr(sBuffer, vbNullChar) - 1)
      14. ' MCI öffnen
      15. lResult = mciSendString("open " & sFile & _
      16. " type MPEGVideo alias " & sAlias, 0, 0, 0)
      17. If lResult = 0 Then
      18. ' MP3 abspielen
      19. If mciSendString("play " & sAlias & _
      20. " from 0", 0, 0, 0) = 0 Then
      21. bResult = True
      22. End If
      23. End If
      24. End If
      25. MP3_Play = bResult
      26. End Function
      27. #End Region
      28. #Region " Wiedergabe stoppen und MCI schließen "
      29. Private Sub MP3_Stop(ByVal sAlias As String)
      30. mciSendString("stop " & sAlias, 0, 0, 0)
      31. mciSendString("close " & sAlias, 0, 0, 0)
      32. End Sub
      33. #End Region
      34. Private Sub cmdPlay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPlay.Click
      35. OpenDialog.DefaultExt = "mp3"
      36. OpenDialog.ShowDialog()
      37. TextBox_mp3.Text = OpenDialog.FileName
      38. MP3_Play(TextBox_mp3.Text, "MyAlias")
      39. End Sub
      40. Private Sub cmdPause_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPause.Click
      41. mciSendString("pause " + TextBox_mp3.Text, 0, 0, 0)
      42. End Sub
      43. Private Sub cmdStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdStop.Click
      44. MP3_Stop("MyAlias")
      45. End Sub
      46. End Class

      Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „Agent“ ()