MP3 länge auslesen

    • Allgemein

      MP3 länge auslesen

      VB NET: MP3 länge auslesen

      VB.NET-Quellcode

      1. Imports System
      2. Imports System.Collections.Generic
      3. Imports System.Text
      4. Imports Shell32
      5. Public Class Form1
      6. 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
      7. Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Integer) As Integer
      8. Private Function GetMP3Length(ByVal strFileName As String) As Long
      9. Dim strBuffer As String
      10. Dim lRet As Long
      11. Dim sReturn As String
      12. ' Da die mciSendString Funktion mit langen Dateinamen
      13. ' nicht korrekt arbeitet, muss zuvor der kurze
      14. ' 8.3 Dateiname der MP3-Datei ermittelt werden.
      15. strBuffer = Space$(255)
      16. lRet = GetShortPathName(strFileName, strBuffer, Len(strBuffer))
      17. If lRet <> 0 Then
      18. strFileName = Microsoft.VisualBasic.Left(strBuffer, InStr(strBuffer, vbNullChar) - 1)
      19. End If
      20. ' MP3-Datei öffnen
      21. mciSendString("open " & strFileName & _
      22. " type MPEGVideo alias mp3audio", 0, 0, 0)
      23. ' Länge der Datei in Millisekunden auslesen
      24. sReturn = Space$(256)
      25. lRet = mciSendString("status mp3audio length", _
      26. sReturn, Len(sReturn), 0&)
      27. ' MP3-Datei schliessen
      28. mciSendString("close mp3audio", 0, 0, 0)
      29. GetMP3Length = Val(sReturn)
      30. End Function
      31. Private Function FormatTime(ByVal lMSec As Long) _
      32. As String
      33. Dim iMin As Integer
      34. Dim iSec As Integer
      35. iSec = Int(lMSec / 1000)
      36. iMin = Int(iSec / 60)
      37. iSec = iSec - (iMin * 60)
      38. FormatTime = Format$(iMin, "00") & ":" & _
      39. Format$(iSec, "00")
      40. End Function
      41. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
      42. MsgBox(FormatTime(GetMP3Length("C:\000.mp3"))) 'wird länge MP3 angezeigt
      43. End Sub
      44. End Class