Воспроизведение файлов формата MP3 - VB

Формулировка задачи:

Подскажите, пожалуйста: как в VB воспроизвести файл формата MP3?

Код к задаче: «Воспроизведение файлов формата MP3 - VB»

textual
Option Explicit
Private Declare Function mciSendString Lib "winmm.dll" _
 Alias "mciSendStringA" (ByVal lpszCommand As String, _
 ByVal lpszReturnString As String, _
 ByVal cchReturnLength As Long, _
 ByVal hwndCallback As Long) As Long
 
Private Declare Function GetShortPathName Lib "kernel32" _
 Alias "GetShortPathNameA" (ByVal lpszLongPath As String, _
 ByVal lpszShortPath As String, _
 ByVal cchBuffer As Long) As Long
 
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 = Left$(sBuffer, InStr(sBuffer, vbNullChar) - 1)
  lResult = mciSendString("open " & sFile & _
   " type MPEGVideo alias " & sAlias, 0, 0, 0)
  
  If lResult = 0 Then
   If mciSendString("play " & sAlias & _
    " from 0", 0, 0, 0) = 0 Then
    bResult = True
   End If
  End If
 End If
 
 MP3_Play = bResult
End Function
 
Public Sub MP3_Stop(ByVal sAlias As String)
 mciSendString "stop " & sAlias, 0, 0, 0
 mciSendString "close " & sAlias, 0, 0, 0
End Sub
 
Private Sub Command1_Click()
  MP3_Play "G:\~Музыка~\Dvar\2000 - Taai liira (demo)\taai-liira.mp3", "MyAlias"
End Sub
 
Private Sub Command2_Click()
 MP3_Stop "MyAlias"
End Sub

8   голосов, оценка 3.375 из 5


СОХРАНИТЬ ССЫЛКУ