BSStreamX is a control that allows you to embed any file in your application, when the application file is brought to another computer there is no need to carry the file that you have embedded in BSStreamX because it is already embedded inside.
In this article, I show you how to merge MP3 files and play MP music in Excel VBA.
'---CODE----
Option Explicit
'Huong dan lap trinh Windows API - Chay nhac MP3
'Nguyen Duy Tuân - http://bluesofts.net
'Facebook: https://www.facebook.com/groups/hocexcel
#If VBA7 Then
Private Declare PtrSafe Function mciSendString Lib "Winmm.dll" Alias "mciSendStringW" ( ByVal lpszCommand As String, ByVal lpszReturnString As String, ByVal cchReturn As Long, ByVal hwndCallback As LongPtr) As Long
#Else
Private Declare Function mciSendString Lib "Winmm.dll" Alias "mciSendStringW" ( ByVal lpszCommand As String, ByVal lpszReturnString As String, ByVal cchReturn As Long, ByVal hwndCallback As Long) As Long
#End If
'--------------------------------------------------------
Sub DoPLAY()
Dim sFileMP3 As String
Dim sCmd As String
Dim x As Long
DoSTOP
'"C:\DATA\My Music\Em Oi Ha Noi Pho - My Hanh.mp3"
sFileMP3 = GetPathTemp & Sheet1.BSStreamX1.Key
If Not FileExists(sFileMP3) Then 'Check file not exists then save from BSStreamX
Sheet1.BSStreamX1.SaveToFile sFileMP3 'Save binary from BSStream to file
End If
If FileExists(sFileMP3) Then
sCmd = "OPEN """ & sFileMP3 & """ alias tuan"
'OPEN
x = mciSendString(U(sCmd), "", 0, 0)
Debug.Print x 'x=0 =>Success
'PLAY
x = mciSendString(U("PLAY tuan"), "", 0, 0)
Debug.Print x
Else
Err.Raise 1005, "", "File not exists."
End If
End Sub
'--------------------------------------------------------Sub DoSTOP() mciSendString U("STOP tuan"), "", 0, 0 mciSendString U("CLOSE tuan"), "", 0, 0 End Sub '--------------------------------------------------------Function U(ByVal s As String) As String U = StrConv(s, vbUnicode) End Function |
