TotalBeginner201
New Member
- Joined
- Oct 24, 2021
- Messages
- 2
- Office Version
- 365
- 2016
- Platform
- Windows
Hello,
Here is my problem. I want to display a video file with *.avi or *.mp4 extension using mciSendString.The file is located on my hard drive. I've already found two methods posted on mrexcel:
I used both of them, changing the api declarations by adding ptrsafe. I also put my file's full path.
First approach modificated with ptrsafe in code module:
The code executes. I am not getting any errors. However nothing happens.
Everything runs fine when I try to play an mp3. I can hear the mp3 file being played:
The second approach involves using an userform. I tried it with userform_click event. In userform module i put the following:
Still nothing happens .
In Multimedia:Playing a Device there is info that:
"
Your application can specify the following options to define the playback window for playing an AVI file:
and
"When the MCIAVI driver creates the playback window or obtains a window handle from your application, it does not display the window until your application either plays the sequence or sends a command to display the window. Your application can use the window command to display the window without playing the sequence. For example, the following command displays the window using mciSendString"
I know that there is a windows media player control. I used it and it works ok. I prefer something like mci because it doesn't require the user of workbook to add reference.
Here is my problem. I want to display a video file with *.avi or *.mp4 extension using mciSendString.The file is located on my hard drive. I've already found two methods posted on mrexcel:
I used both of them, changing the api declarations by adding ptrsafe. I also put my file's full path.
First approach modificated with ptrsafe in code module:
VBA Code:
Public Declare PtrSafe Function sndPlaySound32 _
Lib "winmm.dll" _
Alias "sndPlaySoundA" ( _
ByVal lpszSoundName As String, _
ByVal uFlags As Long) As Long
Public Declare PtrSafe Function mciSendString Lib "winmm.dll" Alias _
"mciSendStringA" (ByVal lpstrCommand As String _
, ByVal lpstrReturnString As String, ByVal uReturnLength As Long _
, ByVal hwndCallback As Long) As Long
Declare PtrSafe Function GetActiveWindow Lib "USER32" () As Integer
Const WS_CHILD = &H40000000
Sub PlayAVIFile()
'Dimension variables.
Dim CmdStr As String, FileSpec As String
Dim Ret As Integer, XLSHwnd As Integer
'The name and location of the AVI file to play.
FileSpec = "C:AVIFilesE-MailScanemail.avi" 'C:AVIFilesCommconnectmodemld.avi"
'Get the active sheet's window handle.
XLSHwnd = GetActiveWindow()
'Opens the AVIVideo and creates a child window on the sheet
'where the video will display. "Animation" is the device_id.
CmdStr = ("open " & FileSpec & _
" type AVIVideo alias animation parent " & _
LTrim$(Str$(XLSHwnd)) & " style " & LTrim$(Str$(WS_CHILD)))
Ret = mciSendString(CmdStr, 0&, 0, 0)
'Put the AVI window at location 25, 120 relative to the
'parent window (Microsoft Excel) with a size of 160 x 160.
Ret = mciSendString("put animation window at 50 240 160 160", _
0&, 0, 0)
'The wait tells the MCI command to complete before returning
'control to the application.
Ret = mciSendString("play animation wait", 0&, 0, 0)
'Close windows so they don't crash when you exit the application.
Ret = mciSendString("close animation", 0&, 0, 0)
End Sub
The code executes. I am not getting any errors. However nothing happens.
Everything runs fine when I try to play an mp3. I can hear the mp3 file being played:
VBA Code:
Sub PlaympFile()
Dim CmdStr As String, FileSpec As String
Dim Ret As Integer, XLSHwnd As Integer
FileSpec = "C:AVIFilesE-MailScanemail.avi"
XLSHwnd = GetActiveWindow()
CmdStr = "open " & FileSpec & " alias animation"
Ret = mciSendString(CmdStr, 0&, 0, 0)
Ret = mciSendString("play animation wait", 0&, 0, 0)
Ret = mciSendString("close animation", 0&, 0, 0)
End Sub
The second approach involves using an userform. I tried it with userform_click event. In userform module i put the following:
VBA Code:
Private Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr
Private Sub UserForm_Click()
Dim FrmHwnd As String
Dim Ret, L, T, W, H As Long
With Me.Image1
L = .Left
T = .Top
W = .Width
H = .Height
End With
FrmHwnd = FindWindow(vbNullString, Me.Caption) & " Style " & &H40000000
strCommand = "open C:\MyAVI.avi Type avivideo Alias video1 parent " & FrmHwnd
Ret = mciSendString(strCommand, "", 0, 0)
Ret = mciSendString("put video1 window at", L & T & W & H, 0, 0)
Ret = mciSendString("play video1 wait", "", 0, 0)
Ret = mciSendString("close video1", "", 0, 0)
End Sub
Still nothing happens .
In Multimedia:Playing a Device there is info that:
"
Your application can specify the following options to define the playback window for playing an AVI file:
- Use the MCIAVI driver's default pop-up window.
- Specify a parent window and window style that the MCIAVI driver can use to create the playback window.
- Specify a playback window for the MCIAVI driver to use for playback.
- Play the AVI file on a full-screen display.
and
"When the MCIAVI driver creates the playback window or obtains a window handle from your application, it does not display the window until your application either plays the sequence or sends a command to display the window. Your application can use the window command to display the window without playing the sequence. For example, the following command displays the window using mciSendString"
I know that there is a windows media player control. I used it and it works ok. I prefer something like mci because it doesn't require the user of workbook to add reference.