Du bist nicht angemeldet.

[VB.NET] MP3 abspielen

Alex2000

unregistriert

1

Sonntag, 15. Februar 2009, 16:45

MP3 abspielen

Visual Basic Quellcode

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
             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« (15. Februar 2009, 17:57)


Social Bookmarks