Author: Tomas Rutkauskas
Using the TMediaPlayer to play AVI is rather slow. When I play the same movies in
the Windows mediaplayer everything works fine. I tried to import the TActiveMovie
ActiveX control in Delphi 5 but then I get an error message when I want to compile
my program. I can't even delete the control from my form. Is there another "easy"
way to play AVI from Delphi without the delays from MCI?
Answer:
This code plays an AVI movie (in full screen). It links directly to the MCI devices
of Windows.So it should be as fast as possible.
1 procedure TForm1.Button1Click(Sender: TObject);
2 const
3 longName: PChar = 'f:\media\ANIM1.MPG'; {Your complete FileName}
4 var
5 ret, shortName: PChar;
6 err: DWord;
7 begin
8 {Getting the short Name (8:3) of selected file}
9 shortName := strAlloc(521);
10 GetShortPathName(longName, shortname, 512);
11 {Sending a close Command to the MCI}
12 ret := strAlloc(255);
13 err := mciSendString(pchar('close movie'), 0, 0, 0);
14 {No error check because at the first call there is no MCI device to close}
15 {Open a new MCI Device with the selected movie file}
16 err := mciSendString(pchar('open ' + shortName + ' alias movie'), 0, 0, 0);
17 shortName := nil;
18 {If an Error was traced then display a MessageBox with the mciError string}
19 if err <> 0 then
20 begin
21 mciGetErrorString(err, ret, 255);
22 messageDlg(ret, mtInformation, [mbOk], 0);
23 end;
24 {Sending the "play fullscreen command to the Windows MCI}
25 err := mciSendString(pchar('play movie fullscreen'), 0, 0, 0);
26 {Use the following line instead of the above one if you want to play
27 it in screen mode}
28 err := mciSendString(pchar('play movie'), 0, 0, 0);
29 {If an Error was traced then display a MessageBox with the mciError string}
30 if err <> 0 then
31 begin
32 mciGetErrorString(err, ret, 255);
33 messageDlg(ret, mtInformation, [mbOk], 0);
34 end;
35 ret := nil;
36 end;
|