Selasa, 19 Juni 2012

MEMBUAT MEDIA PLAYER MENGGUNAKAN DELPHI 7

                                                          Gambar hasil pembuatan media player

Gambar di atas merupakan tampilan dari hasil pembuatan media player menggunakan DELPHI 7.
Dalam pembuatannya dapat di lihat Listing berikut :


unit musik;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, MPlayer, ComCtrls, FileCtrl, StdCtrls, Buttons,MMSystem,
  Spin;



type
  TForm1 = class(TForm)
    Label2: TLabel;
    Label1: TLabel;
    Panel1: TPanel;
    SpeedButton1: TSpeedButton;
    BitBtn1: TBitBtn;
    panel2: TPanel;
    DriveComboBox1: TDriveComboBox;
    FilterComboBox1: TFilterComboBox;
    DirectoryListBox1: TDirectoryListBox;
    FileListBox1: TFileListBox;
    ProgressBar1: TProgressBar;
    MediaPlayer1: TMediaPlayer;
    Timer1: TTimer;
    Panel3: TPanel;
    Label3: TLabel;
    SpinEdit1: TSpinEdit;
    Label4: TLabel;
    SpinEdit2: TSpinEdit;
    Button1: TButton;
    Button2: TButton;
    procedure SpeedButton1Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure FileListBox1DblClick(Sender: TObject);
    procedure FileListBox1Click(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure MediaPlayer1Click(Sender: TObject; Button: TMPBtnType;
      var DoDefault: Boolean);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
 
 
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation
uses Math;

{$R *.dfm}

procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
panel2.Visible:=SpeedButton1.Down;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
if Label1.Left<-Label2.Width then
Label2.Left:=Panel2.Width
Else
Label2.Left:=Label1.Left - 1;
ProgressBar1.Position:=MediaPlayer1.Position;
end;


procedure TForm1.FileListBox1DblClick(Sender: TObject);
begin
MediaPlayer1.FileName:=FileListBox1.FileName;
MediaPlayer1.Open;
Label2.Caption:=FileListBox1.FileName;
ProgressBar1.Max:=MediaPlayer1.Length;
MediaPlayer1.Play;
ProgressBar1.Position:=MediaPlayer1.Position;
ProgressBar1.Max:=MediaPlayer1.Length;
MediaPlayer1.Enabled:=true;
Timer1.Enabled:=true;
end;

procedure TForm1.FileListBox1Click(Sender: TObject);
begin
MediaPlayer1.Display:=Panel3;
MediaPlayer1.FileName:=FileListBox1.FileName;
MediaPlayer1.Open;
Label2.Caption:=FileListBox1.FileName;
ProgressBar1.Max:=MediaPlayer1.Length;
ProgressBar1.Position:=MediaPlayer1.Position;
ProgressBar1.Max:=MediaPlayer1.Length;
MediaPlayer1.Enabled:=true;
Timer1.Enabled:=true;
end;

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
close;
end;


procedure TForm1.MediaPlayer1Click(Sender: TObject; Button: TMPBtnType;
  var DoDefault: Boolean);
  begin
if Button = btStop then
   begin
     MediaPlayer1.Position:=0;
     ProgressBar1.Position:=0;
   end
 else if Button = btStep then
   begin
     if ((MediaPlayer1.Position+5000)<=MediaPlayer1.Length) then
       MediaPlayer1.Position:=MediaPlayer1.Position+5000
     else
       begin
         MediaPlayer1.Position:=0;
         ProgressBar1.Position:=0;
       end;
     MediaPlayer1.Play;
   end
 else if Button = btBack then
   begin
     if ((MediaPlayer1.Position-5000)>0) then
       MediaPlayer1.Position:=MediaPlayer1.Position-5000
       else
         MediaPlayer1.Position:=0;
         MediaPlayer1.Play;
     end;
     end;


 Function GetWaveVolume(var Lvol:DWORD;var Rvol:DWORD):Boolean;
 var
 waveOutCaps:TWAVEOUTCAPS;
 Volume:DWORD;
 begin
 Result:=false;
 if WaveOutgetDevCaps(WAVE_MAPPER,@ WaveOutCaps,sizeof(WaveOutCaps))=MMSYSERR_NOERROR then
 if WaveOutCaps.dwSupport and WAVECAPS_VOLUME=WAVECAPS_VOLUME then
 begin
 Result:=WaveOutGetVolume(WAVE_MAPPER,@Volume)=MMSYSERR_NOERROR;
 LVol:=LoWord(volume);
 RVol:=HiWord(Volume);
 end;
 end;


Function SetWaveVolume(const AVolume:DWORD):Boolean;
var
WaveOutCaps:TWAVEOUTCAPS;
begin
Result:=False;
if WaveOutGetDevCaps(WAVE_MAPPER,@WAVEOUTCAPS,sizeof(WaveOutCaps))=MMSYSERR_NOERROR then
if WaveOutCaps.dwSupport and WAVECAPS_VOLUME=WAVECAPS_VOLUME then
Result:=WaveOutSetVolume(WAVE_MAPPER,AVolume)=MMSYSERR_NOERROR;
end;



procedure TForm1.Button1Click(Sender: TObject);
var
LVol:Word;
RVol:word;
begin
LVol:=SpinEdit1.Value;
RVol:=SpinEdit2.Value;
SetWaveVolume(MakeLong(LVol,RVol));
end;

procedure TForm1.Button2Click(Sender: TObject);
var
LVol:DWORD;
RVol:DWORD;
begin
if GetWaveVolume(LVol,RVol) then
begin
SpinEdit1.Value:=LVol;
SpinEdit2.Value:=RVol;
end

end;

end.

Tidak ada komentar:

Posting Komentar