Link to home
Start Free TrialLog in
Avatar of unfunf
unfunf

asked on

.AVI Files in TMediaPlayer play WAY too fast.

Alright. I have been designing a media player using the TMediaPlayer component. Getting it to display the .avi file graphics on a TPanel and other such "challenges" were easy enough to overcome; however, when I load up a .avi file and press play, two things happen:
1. The .avi file plays VERY fast, going through frames as fast as the program can handle I assume.
2. There is no sound (probably because it's playing so fast though).

I looked through a bunch of tutorials and they all say just do MediaPlayer1.Open then MediaPlayer1.Play, even for .avi files... So, I do not understand why my .avi files go through the frames so quickly, finishing a 23 minute .avi video in less than a minute...


This is the code:

[code]
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, MPlayer, XPMan, StdCtrls, ExtCtrls, ComCtrls;

type
  TForm1 = class(TForm)
    MediaPlayer1: TMediaPlayer;
    XPManifest1: TXPManifest;
    LabeledEdit1: TLabeledEdit;
    Button1: TButton;
    OpenDialog1: TOpenDialog;
    Panel1: TPanel;
    StatusBar1: TStatusBar;
    Timer1: TTimer;
    procedure Button1Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  if OpenDialog1.Execute then
  begin
    LabeledEdit1.Text := OpenDialog1.FileName;
    MediaPlayer1.FileName := OpenDialog1.FileName;
    if (LowerCase(ExtractFileExt(OpenDialog1.FileName)) = '.avi') or
       (LowerCase(ExtractFileExt(OpenDialog1.FileName)) = '.mpg') or
       (LowerCase(ExtractFileExt(OpenDialog1.FileName)) = '.mpeg') or
       (LowerCase(ExtractFileExt(OpenDialog1.FileName)) = '.mov') then
    begin
      MediaPlayer1.Display := Panel1;
      MediaPlayer1.Open;
      MediaPlayer1.DisplayRect := rect(0, 0, panel1.width, panel1.height);
      Timer1.Enabled := True;
    end else
    begin
      MediaPlayer1.Open;
      Timer1.Enabled := False;
    end;
  end;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
  TotLen, CurPos, PerComp, FPS: Extended;
begin
  MediaPlayer1.TimeFormat := tfMilliseconds;
  TotLen := (MediaPlayer1.Length / 1000) / 60;
  CurPos := (MediaPlayer1.Position / 1000) / 60;
  PerComp := (100 * (CurPos / TotLen));
  FPS :=  (MediaPlayer1.Frames / (MediaPlayer1.Length / 1000));
  StatusBar1.SimpleText := 'Total Length (minutes): '+FloatToStrF(TotLen, ffGeneral, 5, 2)+' | Current Position (minutes): '+FloatToStrF(CurPos, ffGeneral, 5, 2)+' | Percent Complete: %'+IntToStr(Round(PerComp))+' | Frames: '+IntToStr(MediaPlayer1.Frames)+' | FPS: '+IntToStr(Round(FPS));
  StatusBar1.Update;
end;

end.
[/code]
Avatar of sftweng
sftweng

Can you play the files correctly using Windows Media Player? Do you have the codec installed for the format used in the *.avi?
Avatar of unfunf

ASKER

Yes. I can play files fine using any other player, but when I use the TMediaPlayer component in delphi it just seems to try to play the .avi w/ no sound and as fast as it possibly can, so a 30 minute .avi video lasts less than a minute.
ASKER CERTIFIED SOLUTION
Avatar of evil-tech
evil-tech

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of unfunf

ASKER

Well I have a huge mass of codecs called "Ace Mega codecs", could that have done something?
I think not. If the codecs were not corrupted, they will have no influence. Still, if you can play it with normal VfW (Video for Windows) media players like BSPlayer or Windows Media Player, it will be no codec issue.

The Delphi TMediaPlayer (that one with the Delphi 1 speedbutton) is heritage from the Windows 3.1 era.

Like I already said, you should rather use the Windows Media Player 6 ActiveX control. Every user who's using Windows 98 SE, 2000, ME, XP or 2003 will almost be guaranteed to have WMP 6. Those using 95, 98 or NT 4 usually have it too.
Avatar of unfunf

ASKER

Alright I'll try it later today and get back to you. If it works, accept your answer as well of course :).
Avatar of unfunf

ASKER

Is that ActiveX Component available somewhere because I cannot find it. (Delphi 7)