How To Make an Audio And Video Player in Delphi
7
1. Buat design form seperti ini:
2. kemudian ketik listing dibawah ini:
unit Unit1;
interface
uses
Windows, Messages,
SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, MPlayer,
ComCtrls, ExtCtrls, StdCtrls, MMSystem,
XPMan, jpeg;
type
TForm1 =
class(TForm)
Edit1: TEdit;
Button1: TButton;
Label1: TLabel;
Label2: TLabel;
ScrollBar1:
TScrollBar;
Panel1: TPanel;
Panel2: TPanel;
Label3: TLabel;
ProgressBar1:
TProgressBar;
MediaPlayer1:
TMediaPlayer;
Timer1: TTimer;
OpenDialog1:
TOpenDialog;
XPManifest1:
TXPManifest;
Image1: TImage;
procedure
Button1Click(Sender: TObject);
procedure
Timer1Timer(Sender: TObject);
procedure
ScrollBar1Change(Sender: TObject);
procedure
FormCreate(Sender: TObject);
private
{ Private
declarations }
public
{ Public
declarations }
end;
var
Form1: TForm1;
implementation
// Fungsi
GetWaveVolume (untuk mendapatkan volume suara)
function GetWaveVolume:byte;
var
volume:DWORD;
WaveOutCaps:
TWAVEOUTCAPS;
Vol:real;
s:string;
begin
if
WaveOutGetDevCaps(WAVE_MAPPER,@WaveOutCaps,SizeOf(WaveOutCaps))=MMSYSERR_NOERROR
then
begin
WaveOutGetVolume(WAVE_MAPPER,@Volume);
Vol:=(Volume div
65537 div 257);
s:=floattostr(int(vol));
GetWaveVolume:=strtoint(s);
end;
end;
// Fungsi
SetWaveVolume (untuk mengatur volume suara)
function SetWaveVolume(Volume:dword):dword;
var vol:integer;
WaveOutCaps:TWAVEOUTCAPS;
begin
vol:=(Volume)*65537*257;
if
WaveOutGetDevCaps(WAVE_MAPPER,@WaveOutCaps,SizeOf(WaveOutCaps))=MMSYSERR_NOERROR
then
begin
WaveOutSetVolume(WAVE_MAPPER,MakeLong(vol, vol));
end;
end;
{$R *.dfm}
//Double click pada
button1
procedure TForm1.Button1Click(Sender: TObject);
begin
if opendialog1.Execute then
begin
MediaPlayer1.FileName:=opendialog1.FileName;
MediaPlayer1.Display:=panel1;
MediaPlayer1.Open;
MediaPlayer1.Play;
MediaPlayer1.Stop;
ProgressBar1.Position:=MediaPlayer1.Position;
ProgressBar1.Max:=MediaPlayer1.Length;
Timer1.Enabled:=true;
Edit1.Text:=ExtractFileName(opendialog1.FileName); //
fungsi ExtractFileName = untuk mendapatkan nama file saja
Label3.Caption:=OpenDialog1.FileName;
MediaPlayer1.DisplayRect:=Rect(0,0,panel1.Width-0,panel1.Height-0); // agar
ukuran video mengikuti ukuran panel1
end;
end;
//Double click pada Timer1
procedure TForm1.Timer1Timer(Sender: TObject);
begin
if Label3.Left<-Label3.Width then
begin
Label3.Left:=Panel2.Width //agar teks yg berjalan kembali lagi
end
else
Label3.Left:=Label3.Left -1;
//teks berjalan
ProgressBar1.Position:=MediaPlayer1.Position;
end;
//Double click pada ScrollBar1
(untuk mengatur volume)
procedure TForm1.ScrollBar1Change(Sender: TObject);
var f:real;
i:integer;
begin
SetWaveVolume(ScrollBar1.Position);
f:=int(ScrollBar1.Position/ScrollBar1.Max*100);
ScrollBar1.Position:=i;
ScrollBar1.Hint:=IntToStr(i);
end;
//Double click pada Form
procedure TForm1.FormCreate(Sender: TObject);
var i:integer;
begin
i:=GetWaveVolume;
ScrollBar1.Position:=i;
end;
end.
Daftar Component
Nama
|
Letak
|
Panel1
|
Standard
|
Panel2
|
Standard
|
Label3
|
Standard
|
Button1
|
Standard
|
Edit1
|
Standard
|
OpenDialog1
|
Dialogs
|
MediaPlayer1
|
System
|
Timer1
|
System
|
ProgressBar1
|
Win32
|
XPManifest
|
Win32
|
Tidak ada komentar:
Posting Komentar