 |
|
 |
Goran Level: Moderator
 Registered: 16-05-2002 Posts: 1681
|
Re: Avi file
you can play movie files without using any ocx, just using API. I will post here a simple code how to use mciSendString or mciSendCommand functions, depending whether you want to pass comand by passing formatted strings, or binary values/structures. This code will play avi file for 5 seconds only.
Option Explicit
Private Declare 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
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub Command1_Click()
Dim FileName As String
Dim RetVal As Long
' Avi file
FileName = "D:\Goran\My Videos\Funny\Exam.avi"
RetVal = mciSendString("open " & Chr$(34) & FileName _
& Chr$(34) & " type avivideo alias movie", vbNullString, 0, 0)
RetVal = mciSendString("play movie from 0", vbNullString, 0, 0)
Sleep 5000
RetVal = mciSendString&("stop movie", vbNullString, 0, 0)
RetVal = mciSendString&("close movie", vbNullString, 0, 0)
End Sub |
I have used Sleep function for quick demonstration how to stop file playback and close file. You can use timer function instead of sleep, then it wont freeze your form.
____________________________
If you find the answer helpful, please mark this topic as solved.
|
|
27-01-2004 at 04:17 PM |
|
|
Goran Level: Moderator
 Registered: 16-05-2002 Posts: 1681
|
Re: Avi file
Ok, I will remade this code, so you can understand it better
Option Explicit
Private Declare 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
Private Sub PlayAvi()
Dim FileName As String
Dim RetVal As Long
' Avi file
FileName = "D:\Goran\My Videos\Funny\Exam.avi"
RetVal = mciSendString("open " & Chr$(34) & FileName _
& Chr$(34) & " type avivideo alias movie", vbNullString, 0, 0)
RetVal = mciSendString("play movie from 0", vbNullString, 0, 0)
End Sub
Private Sub CloseAvi()
Dim RetVal As Long
RetVal = mciSendString&("stop movie", vbNullString, 0, 0)
RetVal = mciSendString&("close movie", vbNullString, 0, 0)
End Sub |
So, you call PlayAvi. and after its done, CloseAvi. You can go further more and isolate OpenAvi from PlayAvi if you want to play it more times (you cant open avi file twice with same alias). Hope you get it now.
____________________________
If you find the answer helpful, please mark this topic as solved.
|
|
28-01-2004 at 10:21 PM |
|
|
|
|
 |
 |