Results 1 to 19 of 19

Thread: How to play an AVI file in a specific location using API

  1. #1

    Thread Starter
    Hyperactive Member Blinky Bill's Avatar
    Join Date
    Mar 2002
    Location
    Happily munching on the greenery in your garden
    Posts
    349

    How to play an AVI file in a specific location using API

    Hi,
    I want to play an AVI file on my form using the API. I have found some code on AllAPI.net which plays fine, but in another window. I did a search on the web and this site, and found a bas file written by someone here (sorry, can't remember who you are), which promises to play in my form, but doesn't play at all.

    Does anyone have a reliable way of doing this?


    Thanx for all help
    We don't know what's wrong. . . So the best bet might be to remove something surgically.

  2. #2
    Junior Member
    Join Date
    Jan 2002
    Location
    Seoul Korea
    Posts
    20

    Play for AVI File

    The following TIP may be posted in this site and i hope that you can play *.avi file as per the following tip.


    1).Start a new project.
    2).Add a Animation Control to the form. (The animation control is part of "Microsoft Windows Common
    Controls-2 6.0 in the Project Components list.
    3).Add a Command Button (Command1).
    4).Paste the following code into the General Declarations section of the Form.
    5).Edit the code, looking for the "AVIFile = " statement and make sure it has the correct path to the
    "Search.avi" file.
    6).Change the statement which reads "Ret = SearchTreeForFile("C:\", "vb6.exe", tempStr)" to
    the executable of your choice.
    7).Run the program

    '------------- PREPARATION END ---------------------------


    '------------- CODE --------------------------------------


    private Declare Function SearchTreeForFile Lib "imagehlp" (byval RootPath as string, byval InputPathName as string, byval OutputPathBuffer as string) as Long
    private Const MAX_PATH = 260

    private Sub Command1_Click()

    ' Note: Search AVI stuff added by me jgd
    Dim tempStr as string, Ret as Long
    Dim AVIFile as string
    'create a buffer string
    me.Show
    AVIFile = "C:\Program Files\Microsoft Visual Studio\Common\Graphics\Videos\search.avi"
    anmAVI.Open AVIFile
    anmAVI.Play
    'returns 1 when successfull, 0 when failed
    tempStr = string(MAX_PATH, 0)
    Ret = SearchTreeForFile("C:\", "vb6.exe", tempStr)
    anmAVI.Stop
    anmAVI.Close
    If Ret <> 0 then
    MsgBox "Located file at " + Left$(tempStr, InStr(1, tempStr, Chr$(0)) - 1)
    else
    MsgBox "File not found!"
    End If

    End Sub

  3. #3

    Thread Starter
    Hyperactive Member Blinky Bill's Avatar
    Join Date
    Mar 2002
    Location
    Happily munching on the greenery in your garden
    Posts
    349
    Thanx for the code, but can you tell me why it plays small files like the working.avi (flying folders), but not a movie that i have made?
    We don't know what's wrong. . . So the best bet might be to remove something surgically.

  4. #4
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629

    Re: How to play an AVI file in a specific location using API

    Originally posted by Blinky Bill
    ...are), which promises to play in my form, but doesn't play at all.
    have you tried running the sample you found after compiling into an exe ?

    I'v seen samples running avi's, not visible in design mode, but works just fine when running as a compiled exe.

    just a thought
    -= a peet post =-

  5. #5

    Thread Starter
    Hyperactive Member Blinky Bill's Avatar
    Join Date
    Mar 2002
    Location
    Happily munching on the greenery in your garden
    Posts
    349
    Maybe i wasn't clear enough on the reason why it won't play. It gave an error message saying "Type Not Supported when it tried to open the file. So i don't think that compiling will make a difference in this case.
    We don't know what's wrong. . . So the best bet might be to remove something surgically.

  6. #6
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    oh

    well, then I'll try digup some old source code
    -= a peet post =-

  7. #7
    Addicted Member
    Join Date
    Mar 2001
    Location
    Greece
    Posts
    164

    codecs maybe ?

    Usually, when you create a movie file, you use some sophisticated compression codecs like DivX. If this is the case then :

    Maybe the OCX control is not able to use the codecs (decoder) in order to play the AVI.
    It could be it, or it could be that the codecs are not registered properly (try Multimedia on Control Panel, or play the movie with Media Player).

    Why don't you insert a MediaPlayer control in your form ? It will be playing right, but you will have to distribute the OCX of course, which sucks...

  8. #8
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    You could use the mciSendString API to play movies.
    Have a look at this thread for the basics

  9. #9
    Fanatic Member Geespot's Avatar
    Join Date
    Oct 2001
    Location
    Birmingham, UK
    Posts
    577
    I once had a class module that plays avi's into a specified hwnd, it was really cool but that was like 3 years ago and i dont have it know more. But I found it on www.pscode.com and im sure it used mcisendstring as mention above

  10. #10
    Fanatic Member Geespot's Avatar
    Join Date
    Oct 2001
    Location
    Birmingham, UK
    Posts
    577
    umm sorry but planet source code seems to not work no more!

  11. #11

    Thread Starter
    Hyperactive Member Blinky Bill's Avatar
    Join Date
    Mar 2002
    Location
    Happily munching on the greenery in your garden
    Posts
    349
    Just to clarify a few points: I don't want to use an OCX to play it, the code i dug up off allApi.net worked (with a few little bugs) using mcisendstring, but played in a separate window rather than the creating form. The bas file i dug up used mcisendstring combined with the form handle to play in, but wouldn't/couldn't open the avi, except for little ones.

    Thanx all for looking at this.
    We don't know what's wrong. . . So the best bet might be to remove something surgically.

  12. #12
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    I still recommend mciSendString.
    If you don't want it to open a new window, specify the parent in the open command.

    Use the type Sequencer for .mid files, waveaudio for .wav files, CDAudio for .cda files and use MPEGvideo for all the others. Don't use the type AVIVideo for .avi files, the MPEGVideo type yields better results.

    eg
    mciSendString "open " & strFileToPlay & "alias MyVideo type MPEGVideo parent " & Picture1.hwnd, 0, 0, 0

  13. #13
    Lively Member
    Join Date
    May 2002
    Location
    Malaysia
    Posts
    103

    playing avi and wav together

    how about playing an avi and wav file together...is it possible?
    so far I have an avi file which the sound file is actually in other file
    test.avi and test.wav

    do you think I can play both files simutaneously ?..how do I synchronise both files?

  14. #14
    Hyperactive Member
    Join Date
    Mar 2002
    Posts
    424
    Ok, I'm using MciSendString to play avi files. I have a similar to problems that I've scoped out over the forum and haven't found an answer to. Bear in mind that I'm using VBA and that is not compileable (I think). How do you get around the size limit for playing avi files? If I play a small one, no problem. Pick a larger one and I get 'The Driver can not recognize the specified command parameter' and yet I've changed nothing but the file. I'm using some code I found on the forum:
    VB Code:
    1. Public Sub PlayVideo(FilePath As String, PlayIn As Long)
    2. FilePath = UCase(FilePath)
    3. If Right(FilePath, 3) = "AVI" Then
    4. longnum = mciSendString("open " & FilePath & " type Avivideo alias movie style child parent " & PlayIn, 0&, 0, 0)
    5. If longnum <> 0 Then DisplayError longnum
    6. Else
    7. mciSendString "open " & FilePath & " type MPEGvideo alias movie style child parent " & PlayIn, 0&, 0, 0
    8. End If
    9. mciSendString "play movie wait", 0, 0, 0
    10. mciSendString "close movie", 0, 0, 0
    11. End Sub
    Any help would be appreciated.

  15. #15
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    I had similar problems when I used type Avivideo for *.avi files.
    Try using MPEGvideo for avi files as well.

    To quote myself
    Use the type Sequencer for .mid files, waveaudio for .wav files, CDAudio for .cda files and use MPEGvideo for all the others. Don't use the type AVIVideo for .avi files, the MPEGVideo type yields better results.

  16. #16
    Hyperactive Member
    Join Date
    Mar 2002
    Posts
    424
    Actually that's what I'm using. The one file is 83K and plays fine. The other is 5 megs and doesn't play at all. Any other ideas?

    The code I posted is a little older and I'm using MPEGVideo in both circumstances now. Sorry for the confusions. But it's still not working...

  17. #17
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    I have no problems using MPEGVideo, even if the file is 700 MB.
    Of course you need to have the proper codec installed.
    Can you play the movie with another player?

  18. #18
    Hyperactive Member
    Join Date
    Mar 2002
    Posts
    424
    If I use the mplayer it works fine. Just not when I try to launch it with MCISendString. I don't get it. I'm using WINNT and this is in VBA if that makes a difference..

  19. #19
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    Why do you specify style child if you also specify a parent? I don't know if this has anything to do with the problem you have, but it seems a contradiction.

    From MSDN:

    parent hwnd - Specifies the window handle of the parent window.

    style child - Opens a window with a child window style.

    Another possible reason for this error is a space in the path or filename. To avoid this problem, enclose the path and filename in double quotes.

    eg.
    mciSendString "open " & Chr(34) & FilePath & Chr(34) & " type MPEGvideo alias movie style child parent " & PlayIn, 0&, 0, 0

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width