Professional Documents
Culture Documents
n
unit Unit1;
interface
// ---fangan lupa tambahkan " mmsystem " pada " uses " dibawah..
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ComCtrls, MPlayer,
ExtCtrls, mmsystem;
//--- tambah constanta disini untuk mengatur volume
const
// ---- ini buat loading volume ----
MCISETAUDIO $083;
MCIDGVSETAUDIOVOLUME $4002;
MCIDGVSETAUDIOITEM $00800000;
MCIDGVSETAUDIOVALUE $01000000;
MCIDGVSTATUSVOLUME $4019;
type
TForm1 class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
MediaPlayer1: TMediaPlayer;
ListBox1: TListBox;
OpenDialog1: TOpenDialog;
TrackBar1: TTrackBar;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
Button6: TButton;
Timer1: TTimer;
ProgressBar1: TProgressBar;
procedure Mainkan; // tulis manual prosedur ini
procedure FormCreate(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure TrackBar1Change(Sender: TObject);
procedure ListBox1DblClick(Sender: TObject);
procedure ListBox1KeyDown(Sender: TObject; var Key: Word; ShiIt: TShiItState);
private
Private declarations }
// tambahkan " index " berupa integer, untuk playlist index
index:integer;
public
Public declarations }
end;
var
Form1: TForm1;
implementation
# *.dfm}
// tambahkan " type " untuk mengatur seting volume
type
MCIDGVSETAUDIOPARMS record // volume
dwCallback: DWORD;
dwItem: DWORD;
dwValue: DWORD;
dwOver: DWORD;
lpstrAlgorithm: PChar;
lpstrQuality: PChar;
end;
// tambahkan " type " untuk atur status volume
type
MCISTATUSPARMS record // volume
dwCallback: DWORD;
dwReturn: DWORD;
dwItem: DWORD;
dwTrack: DWORD;
end;
// tulis prosedur set volume seperti dibawah
procedure MPSetVolume(MP: TMediaPlayer; Volume: Integer) ;
var
p: MCIDGVSETAUDIOPARMS;
begin
p.dwCallback : 0;
p.dwItem : MCIDGVSETAUDIOVOLUME;
p.dwValue : Volume;
p.dwOver : 0;
p.lpstrAlgorithm : nil;
p.lpstrQuality : nil;
mciSendCommand(MP.DeviceID, MCISETAUDIO, MCIDGVSETAUDIOVALUE or
MCIDGVSETAUDIOITEM, Cardinal(p)) ;
end;
tulis fungsi untuk dapatkan Jolume, range 0 - 1000}
function MPGetVolume(MP: TMediaPlayer): Integer;
var
p: MCISTATUSPARMS;
begin
p.dwCallback : 0;
p.dwItem : MCIDGVSTATUSVOLUME;
mciSendCommand(MP.DeviceID, MCISTATUS, MCISTATUSITEM, Cardinal(p)) ;
Result : p.dwReturn;
end;
// ---------------------------- prosedur mainkan musix or video ---------------
// play musik or video gt loh.. ~,
procedure TIorm1.Mainkan;
var
i:integer;
begin
MediaPlayer1.FileName : listbox1.Items.Strings|index|;
MediaPlayer1.Open;
i:MediaPlayer1.Length div 1000;
Label3.Caption : Iormat('2.2d:2.2d',|i div 60 , i mod 60|);
Label4.Caption : listbox1.Items.Strings|index|;
ProgressBar1.Max : MediaPlayer1.Length ;
MediaPlayer1.Play;
MPSetVolume(MediaPlayer1, TrackBar1.Position );
Timer1.Enabled : true;
Listbox1.ReIresh ;
end;
// prosedure saat form dibuat
procedure TForm1.FormCreate(Sender: TObject);
begin
// ganti caption form
Iorm1.Caption : 'Player dengan TMediaPlayer Delphi..';
// mengedit tampilan dan ukuran TLabel...
Label1.Caption : '00:00';
Label1.Font.Size : 18;
Label2.Caption : 'Total waktu :';
Label2.Font.Size : 12;
Label3.Caption : '00:00';
Label3.Font.Size : 12;
Label4.Caption : 'Title';
Label5.Caption : 'Volume:';
Label6.Caption : '* Press - Delete - pada keyboard untuk menghapus Iile pada playlist';
//menyembunyikan TMediaPlayer
MediaPlayer1.Visible : False;
//mengedit TTrackbar
Trackbar1.TickStyle : tsNone;
Trackbar1.TickMarks : tmBoth;
Trackbar1.Max :1000; //diset nilai maximum jadi 1000, (nanti buat Volume)
Trackbar1.Position : Trackbar1.Max ;
//mengedit TButton
button1.Caption : 'Play';
button2.Caption : 'Pause';
button3.Caption : 'Stop';
button4.Caption : ' prev';
button5.Caption : 'Next ~~';
button6.Caption : 'Open File';
//memfilter TOpendialog
opendialog1.Filter :
'File multimedia
(*.wav,*.mid,*.wmv,*.wma,*.mp3,*.mpg,*.mpeg,*.avi)'',*.wav;*.mid;*.wmv;*.wma;*.mp3;*.mpg;*.mpeg;*.avi';
//mengedit TTimer
Timer1.Enabled : Ialse;
Timer1.Interval : 250;
end;
// prosedur memanggil file ato open file
procedure TForm1.Button6Click(Sender: TObject);
begin
if opendialog1.Execute then begin
if opendialog1.FileName '' then begin
//Tidak lakukan apa2
end else if mediaplayer1.FileName '' then begin
listbox1.Items.Add(opendialog1.FileName );
index:0;
Mainkan;
Listbox1.ItemIndex : index;
end else begin
listbox1.Items.Add(opendialog1.FileName );
end;
end;
end;
ni prosedur timernya.. (mengatur posisi progressbar n fika musik habis ke file selanfutnya ato kembali ke awal)}
procedure TForm1.Timer1Timer(Sender: TObject);
var
i:LongInt;
begin
ProgressBar1.Position : MediaPlayer1.Position ;
i : ProgressBar1.Position div 1000;
label1.Caption : Format ('2.2d:2.2d', |i div 60, i mod 60|);
if label1.Caption label3.Caption then begin
index : index 1;
Listbox1.ItemIndex : index;
if Listbox1.itemindex ~ (index) then begin
index:0;
Mainkan;
Listbox1.ItemIndex : index;
end else begin
Mainkan;
Listbox1.ItemIndex : index;
end;
end;
end;
// prosedur tombol play / tombol 1 saat diklik
procedure TForm1.Button1Click(Sender: TObject);
begin
if ListBox1.Items.Count 0 then begin
// fika playlist kosong bari ga ngapa-ngapain..
end else if MediaPlayer1.Mode mppaused then begin
MediaPlayer1.StartPos : ProgressBar1.Position;
MediaPlayer1.Play ;
Timer1.Enabled : true;
end else if MediaPlayer1.Mode mpPlaying then begin
// fika musik lagi main brati ga ngopo ngopo..
end else begin
Mainkan;
ListBox1.ItemIndex : index;
end;
end;
// prosedur tombol pause
procedure TForm1.Button2Click(Sender: TObject);
begin
if MediaPlayer1.FileName '' then begin
// ga ngapa-ngapain
end else if (MediaPlayer1.Mode mpPaused) then begin
// ga ngapa-ngapain
end else begin
MediaPlayer1.Pause ;
Timer1.Enabled : Ialse;
end;
end;
// prosedur tombol stop
procedure TForm1.Button3Click(Sender: TObject);
begin
if MediaPlayer1.FileName '' then begin
// ga ngapa-ngapain
end else begin
MediaPlayer1.Stop ;
Timer1.Enabled : Ialse;
label1.Caption : '00:00';
ProgressBar1.Position : 0;
end;
end;
// prosedur tombol next
procedure TForm1.Button5Click(Sender: TObject);
begin
if Listbox1.Items.Count 0 then begin
// ngalamun
end else begin
index : index 1;
Listbox1.ItemIndex : index;
if Listbox1.itemindex ~ (index) then begin
index:0;
Mainkan;
Listbox1.ItemIndex : index;
end else begin
Mainkan;
Listbox1.ItemIndex : index;
end;
end;
end;
// prosedur tombol prev
procedure TForm1.Button4Click(Sender: TObject);
begin
if Listbox1.Items.Count 0 then begin
// ngalamun
end else begin
index : index - 1;
Listbox1.ItemIndex : index;
if Listbox1.itemindex - 1 then begin
index:Listbox1.Items.Count - 1 ;
Mainkan;
Listbox1.ItemIndex : index;
end else begin
Mainkan;
Listbox1.ItemIndex : index;
end;
end;
end;
// prosedure saat volume diubah
procedure TForm1.TrackBar1Change(Sender: TObject);
begin
MPSetVolume(MediaPlayer1, Trackbar1.Position );
end;
// double klik pada playlist, music or video maen
procedure TForm1.ListBox1DblClick(Sender: TObject);
begin
index: Listbox1.ItemIndex ;
Mainkan;
end;
// prosedur saat dipencet tombol delete pada keyboard
procedure TForm1.ListBox1KeyDown(Sender: TObject; var Key: Word; ShiIt: TShiItState);
var
DeleteIndex:Integer;
begin
if key VKDelete then begin
deleteIndex: Listbox1.ItemIndex ;
Listbox1.Items.Delete(DeleteIndex);
end;
end;
end.
// -- Script selesai --