borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (regarding listviews)Next Topic (Cool Way To Make A Todo List) New Topic New Poll Post Reply
AndreaVB Forum : VB.Net : Avi file
Poster Message
patriciam
Level: Guest


icon Avi file

Hi!
How can i play an avi file without using media player.
Tanks!

27-01-2004 at 11:08 AM
| Quote Reply
Goran
Level: Moderator

Registered: 16-05-2002
Posts: 1681
icon 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
View Profile Send Email to User Show All Posts | Quote Reply
patriciam
Level: Guest

icon Re: Avi file

Hi Goran!
But, if i want to play more than 5 seconds, i must change the value of sleep?
Tanks a lot!

28-01-2004 at 09:58 AM
| Quote Reply
Goran
Level: Moderator

Registered: 16-05-2002
Posts: 1681
icon 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
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : VB.Net : Avi file
Previous Topic (regarding listviews)Next Topic (Cool Way To Make A Todo List) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder