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(
OpenDialog
1.FileName
)) = '.avi') or
(LowerCase(ExtractFileExt(
OpenDialog
1.FileName
)) = '.mpg') or
(LowerCase(ExtractFileExt(
OpenDialog
1.FileName
)) = '.mpeg') or
(LowerCase(ExtractFileExt(
OpenDialog
1.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.Fr
ames)+' | FPS: '+IntToStr(Round(FPS));
StatusBar1.Update;
end;
end.
[/code]