We help IT Professionals succeed at work.

DSPack playing / Controlling movie through DLL

AuthorwareXtras
on
Medium Priority
1,457 Views
Last Modified: 2010-04-05
I want to use use DSPack from with a DLL to create a video window and play back a video.  The video window should be created within another non delphi application by calling the DLL from that application.  Creating a DLL and calling it from another application is not a problem, it is just the DSPack elements I am having trouble with.

I have tried this so far:

  //create the filter graph
   FilterGraph := TFilterGraph.Create(nil);

   //I tried both these options below
  //VideoWindow := TVideoWindow.Create(nil);
   VideoWindow := TVideoWindow.CreateParented(AW.hwnd);  //AW.hwnd is the Window Handle of the application calling the DLL, so I have the handle OK

  VideoWindow.FilterGraph:= FilterGraph;
 
//Just hard coding these values at the minute until I get it working.  They will ultimately be passed as part of the DLL call
  VideoWindow.Left:=10;
  VideoWindow.Top:=10;
  VideoWindow.Width := 320;
  VideoWindow.Height := 240;
  VideoWindow.Visible:=true;

  FilterGraph.Active := true;
  //FilterGraph.ClearGraph;  
  FilterGraph.RenderFile(strFileToPlay);  
  FilterGraph.Play;

If I un-comment FilterGraph.ClearGraph I get an access violation.  if I comment it out, I don't get an access violation, but neither do I get a video window with a video playing.  When I close the application calling the DLL I get the standard "program has encountered a problem and needs to close" dialog box inviting me to imform uncle Bill!  Maybe the Video Window has not been cleanly destroyed??

Ultimately I wish to do the 'standard' things you may wish to do with a video such as play pause, stop etc as well as respond to events from the DSPack components from within the DLL

Any help appreciated.
Comment
Watch Question

Top Expert 2007

Commented:
you're not doing it right. you don't create the videowindow, but you query for it. and then you can try the put_woner ethod, though I never tried that. here is a demo to get you started: http://www.ciuly.com/delphi/multimedia/dspackStreamPlayer/index.html 
it has a lot of unnecessary stuff for you, but it also has the player which you can use.

Author

Commented:
Can't get that to work.  I follow the instructions and end up wth a player.exe file but launching that gives an error and opening the dpr tells me there are components missing.
Top Expert 2007

Commented:
then you did not follow all the instructions. make sure the directory structure is as explained (even if you have dspack installed: it doesn't matter, just extract from the original zip in another directory, they will not collide).
also, I see now that it's not logical for the folowing to be done from those instructions: put a test.mpg file in "the merger" directory. you can download the sample from my site if you don't have one.

Author

Commented:
I did follow the instructions.

It now works after I put the video in plave in that I can run the exe and see the video.  I am failing to see how this helps me though as I open the ThePlayer.dpr file and I get the dialog telling me that I am missing TStreamFilter, TMyFilterGraph and TFileStreamWrapper
Top Expert 2007

Commented:
that is because the components are not isntalled ;) that is a command line build process that does not make use of installed components. it's actually retty nice when you want to try something and don't want to install it in the IDE.

anyway, getting back to your porblem: what will help you is the actual player. you can see the code how the player is created and how to work with the videowindow which is your actuall problem. then, where I do:
      FilterGraph.QueryInterface(IVideoWindow, VideoWindow);
      if VideoWindow<>nil then
      begin
        VideoWindow.get_Visible(isVideoVisible);
        VideoWindow.put_Caption('My Async Player');
        VideoWindow.put_Left(0);
        VideoWindow.put_Top(0);
        VideoWindow.put_WindowStyle(WS_DLGFRAME);
        VideoWindow.put_AutoShow(true);
      end;

you also add the line
VideWindow.put_Owner(AW.hwnd);// as I said, I never tried this but makes sens.

for testing purposes, you can use the already existing form2 from the package (which btw is not used. I see that I forgot it there. the demo is a strip of a fully functional player and form2 is used for MCI playback if I recall correctly).
anyway, I'll do some modification for you if you can't get it by yourself, but only after about 30-40 min as I have something that I need to finish first.

Author

Commented:

I think I am missing something here, so I will wait for your example.

Thanks very much.  :-)
Top Expert 2007

Commented:
sorry for the late response. I had some things to take care of and of course I forgot a very small line from the code and it took me a few hours until I realised why it didn't work :D (forgot to render the file :)) )

so, I made a stripped down project: only a player that will make the videowindow appear on a different window (form2 in this case) available on that same page I have given you (direct project link: http://www.ciuly.com/delphi/multimedia/dspackStreamPlayer/index.html)

Author

Commented:
Hi

Source - Player Only links to the same page and not the source:  http://www.ciuly.com/delphi/multimedia/dspackStreamPlayer/index.html

Top Expert 2007
Commented:
true. sorry. was kind of late last night and didn't pay attention to what actually happened there as I've doen this a lot of times.
I corrected the link: http://www.ciuly.com/delphi/multimedia/dspackStreamPlayer/dspack_player_only.zip

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
I have that working now thanks very much and will accept that as the answer.  I just have a couple of questions on this solution:

1. Is there anything that can be returned to the calling application (handle, object pointer?) so that it can be used in subsequent function calls to work on the movie window, so for example, if the application calls the DLL with PlayMovie(strFilename, intLeft, intTop) can the function return a handle or something, so that subsequently a second function such as MoviePause (Handle, blnPause) //true or false can be used??

2. The application calling the DLL gives an error on exit currently.  I assume this is related to the fact the movie window has not been closed gracefully.  This probably therefore refers to the previous question in that I will need a function like CloseMovie(handle)  ??

3. The movie appears and plays, but seems to 'jump' to it's required location as opposed to appearing there.  Any idea what may be causing that.

Thanks for your help once more.
Top Expert 2007

Commented:
1. sure. you return a reference to filtergraph like function PlayMovie(strFilename MAKE this pchar or include the sharemem usnit for string. see teh comment when creating a dll, intLeft, intTop):TFilterGraph;

2. true. you will have to cal FilterGraph.ClearGraph; when finishing

3. try the following. seems to work ok:
      FilterGraph.RenderFile(filename);
      FilterGraph.QueryInterface(IVideoWindow, VideoWindow);
      form2.show;
      if VideoWindow<>nil then
        videoWindow.put_Owner(form2.Handle);
      FilterGraph.Play;

      if VideoWindow<>nil then
      begin
        VideoWindow.get_Visible(isVideoVisible);

I didn't see that jump before either, but this might fix it in case it was just too fast for my eyes :)

Author

Commented:
Thanks I will give it all a try....The maybe don't see the jump because the window I am putting the video on to is there already instead of form2.show here.....

Author

Commented:
I almost have it!  I am trying the following:

Function EraseMovie(FilterGraph:TFilterGraph):Boolean;stdcall;
begin
  try
     FilterGraph.Stop;
     FilterGraph.ClearGraph;
     //FilterGraph.Destroy;
     Result:= true;
     except on E:Exception do
        begin
        showmessage(E.Message);
        result:=false;
        end;
     end;
end;

The movie window erases, but the application throws an exception still on exit....any ideas?
Top Expert 2007

Commented:
use FilterGraph.Free; not destroy if you want to distroy the filtergraph, though only do that if you manually created it and not placed it on a form. if you placed it on a form, then leave it for the form to distroy it (you can also reuse it, since you cleared it ;) )

but what is the exception?

Author

Commented:
You will notice that Destroy is commented out.  I tried it as a last resort after trying free.  Using FilterGraph.Free hangs the application.

using:

     FilterGraph.Stop;
     FilterGraph.ClearGraph;

Removes the window but when the application is closed it shows the windows "Program has encountered a problem and needs to close" dialog inviting me to tell uncle Bill about it.  This is what was happening before I was removing the window and I assumed it was because the window was still present, but that seems not to be the case.


Top Expert 2007

Commented:
the problem could lies somewhere else. can you make a small demo with dll and how you are using everything that reproduces this behaviour? so that I can find what you migt be doing wrong.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.