Membuat MediaPlayer Menggunakan EwMediaPlayer ActiveX Control

D2 TEKNIK KOMPUTER (BSI PROGRAMMER)


Membuat Aplikasi MediaPlayer Menggunakan EwMediaPlayer Pada Delphi 2010
1. Install EwMediaPlayer ActiveX Control
2. Menggunakan link berikut yang sudah ada project EwMediaPlayer


Download EwMediaPlayer||Project_EwMediaPlayer_BSIPROGRAMMER||


Screen Shut Program : 

 




Kemudian coding form mediaplayer sebagai berikut : 
--------------------------------------------------------------------------------------------------
unit play;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  OleCtrls, EWMediaLib_TLB, StdCtrls, Spin, ComCtrls,
  ExtCtrls;

type
  TForm1 = class(TForm)
    EWMedia1: TEWMedia;
    ComboBox1: TComboBox;
    ComboBox2: TComboBox;
    Label7: TLabel;
    Label2: TLabel;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    GroupBox1: TGroupBox;
    RadioButton1: TRadioButton;
    RadioButton2: TRadioButton;
    Label3: TLabel;
    Button5: TButton;
    GroupBox2: TGroupBox;
    RadioButton3: TRadioButton;
    RadioButton4: TRadioButton;
    RadioButton5: TRadioButton;
    RadioButton6: TRadioButton;
    RadioButton7: TRadioButton;
    RadioButton8: TRadioButton;
    RadioButton9: TRadioButton;
    RadioButton10: TRadioButton;
    RadioButton11: TRadioButton;
    Edit1: TEdit;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    CheckBox1: TCheckBox;
    CheckBox2: TCheckBox;
    Edit2: TEdit;
    Label1: TLabel;
    Label8: TLabel;
    TrackBar1: TTrackBar;
    TrackBar2: TTrackBar;
    CheckBox3: TCheckBox;
    GroupBox3: TGroupBox;
    TrackBar3: TTrackBar;
    TrackBar4: TTrackBar;
    TrackBar5: TTrackBar;
    TrackBar6: TTrackBar;
    TrackBar7: TTrackBar;
    TrackBar8: TTrackBar;
    TrackBar9: TTrackBar;
    TrackBar10: TTrackBar;
    TrackBar11: TTrackBar;
    TrackBar12: TTrackBar;
    Label9: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    Label14: TLabel;
    Label15: TLabel;
    Label16: TLabel;
    Label17: TLabel;
    Label18: TLabel;
    Label19: TLabel;
    Label20: TLabel;
    Label21: TLabel;
    OpenDialog1: TOpenDialog;
    ScrollBar1: TScrollBar;
    Timer1: TTimer;
    SaveDialog1: TSaveDialog;
    Label22: TLabel;
    Image1: TImage;
    GroupBox4: TGroupBox;
    RadioButton12: TRadioButton;
    RadioButton13: TRadioButton;
    Label23: TLabel;
    ScrollBar2: TScrollBar;
    Label24: TLabel;
    Label25: TLabel;
    Label26: TLabel;
    TrackBar13: TTrackBar;
    Label27: TLabel;
    Label28: TLabel;
    TrackBar14: TTrackBar;
    Label29: TLabel;
    Label30: TLabel;
    Label31: TLabel;
    Label32: TLabel;
    Label33: TLabel;
    Label34: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure TrackBar2Change(Sender: TObject);
    procedure TrackBar1Change(Sender: TObject);
    procedure TrackBar3Change(Sender: TObject);
    procedure TrackBar4Change(Sender: TObject);
    procedure TrackBar5Change(Sender: TObject);
    procedure TrackBar6Change(Sender: TObject);
    procedure TrackBar7Change(Sender: TObject);
    procedure TrackBar8Change(Sender: TObject);
    procedure TrackBar9Change(Sender: TObject);
    procedure TrackBar10Change(Sender: TObject);
    procedure TrackBar11Change(Sender: TObject);
    procedure TrackBar12Change(Sender: TObject);
    procedure RadioButton3Click(Sender: TObject);
    procedure RadioButton4Click(Sender: TObject);
    procedure RadioButton5Click(Sender: TObject);
    procedure RadioButton6Click(Sender: TObject);
    procedure RadioButton7Click(Sender: TObject);
    procedure RadioButton8Click(Sender: TObject);
    procedure RadioButton9Click(Sender: TObject);
    procedure RadioButton10Click(Sender: TObject);
    procedure RadioButton11Click(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure CheckBox2Click(Sender: TObject);
    procedure Edit1Change(Sender: TObject);
    procedure ComboBox1Change(Sender: TObject);
    procedure ComboBox2Change(Sender: TObject);
    procedure RadioButton1Click(Sender: TObject);
    procedure RadioButton2Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure ScrollBar1Scroll(Sender: TObject; ScrollCode: TScrollCode;
      var ScrollPos: Integer);
    procedure Button5Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure RadioButton12Click(Sender: TObject);
    procedure RadioButton13Click(Sender: TObject);
    procedure ScrollBar2Change(Sender: TObject);
    procedure TrackBar13Change(Sender: TObject);
    procedure TrackBar14Change(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  postype : Integer;
  text : String;
  ismove : Boolean;
  ofile : String;
  infostr : String;
  peaks : array[0..20] of integer;
implementation

{$R *.DFM}


procedure tickertext();
begin
If Form1.RadioButton3.Checked Then
  postype := 0;

If Form1.RadioButton4.Checked Then
  postype := 1;

If Form1.RadioButton5.Checked Then
  postype := 2;

If Form1.RadioButton6.Checked Then
  postype := 3;

If Form1.RadioButton7.Checked Then
  postype := 4;

If Form1.RadioButton8.Checked Then
  postype := 5;

If Form1.RadioButton9.Checked Then
  postype := 6;

If Form1.RadioButton10.Checked Then
  postype := 7;

If Form1.RadioButton11.Checked Then
  postype := 8;

text := Form1.Edit1.text;
If Form1.CheckBox1.Checked = True Then
ismove := True
Else
ismove := False;

Form1.EWMedia1.SetTextColor(255, 0, 0);
//ewmedia1.SetTextFont "Arial", 20, False, False, False
Form1.EWMedia1.SetTickerText(text);
If Form1.CheckBox1.Checked = True Then
   Form1.EWMedia1.StartTickerSlide(postype, ismove, round( strtofloat(Form1.Edit2.text) * 1000.0))
Else
   Form1.EWMedia1.StopTickerSlide;
End;

procedure seteq();
var val1 : Single;
    val2 : Single;
    val3 : Single;
    val4 : Single;
    val5 : Single;
    val6 : Single;
    val7 : Single;
    val8 : Single;
    val9 : Single;
    val10 : Single;
begin

val1 := - Form1.TrackBar3.Position / 120.0 * 12.0;
val2 := - Form1.TrackBar4.Position / 120.0 * 12.0;
val3 := - Form1.TrackBar5.Position / 120.0 * 12.0;
val4 := - Form1.TrackBar6.Position / 120.0 * 12.0;
val5 := - Form1.TrackBar7.Position / 120.0 * 12.0;
val6 := - Form1.TrackBar8.Position / 120.0 * 12.0;
val7 := - Form1.TrackBar9.Position / 120.0 * 12.0;
val8 := - Form1.TrackBar10.Position / 120.0 * 12.0;
val9 := - Form1.TrackBar11.Position / 120.0 * 12.0;
val10 := - Form1.TrackBar12.Position / 120.0 * 12.0;
Form1.EWMedia1.Equalizer(val1, val2, val3, val4, val5, val6, val7, val8, val9, val10);
End;

Function stotime(time : Double) : String;
var hh : Integer;
    mm : Integer;
    ss : Integer;
begin
  try
  hh:=0;
  mm:=0;
  ss:=0;
  if(time<3600.0) then hh := 0 else hh := trunc(int(time / 3600.0));
  if(time<60.0) then mm := 0 else mm := trunc(int((time - hh * 3600.0) / 60.0));
  if(time>1) then ss := round(time - hh * 3600.0 - mm * 60.0);
  except
   hh:=0;
  end;
  If ss = 60 Then
  begin
    ss := 0;
    mm := mm + 1;
  End;
  If mm = 60 Then
  begin
    mm := 0;
    hh := hh + 1;
  End;
  result := inttostr(hh) + ':' + inttostr(mm) + ':' + inttostr(ss);
End;

procedure TForm1.FormCreate(Sender: TObject);
var volume : integer;
var handle : integer;
begin

RadioButton2.Checked := True;
RadioButton5.Checked := True;
Checkbox1.Checked := False;
//video effects
ComboBox1.Items.Add('None');
ComboBox1.Items.Add('Flip');
ComboBox1.Items.Add('Mirror');
ComboBox1.Items.Add('Emboss');
ComboBox1.Items.Add('GrayScale');
ComboBox1.Items.Add('Negate');
ComboBox1.Items.Add('RGB');
ComboBox1.Items.Add('Brightness');
ComboBox1.Items.Add('Contrast');
ComboBox1.Items.Add('Windy');
ComboBox1.Items.Add('Sharp');
ComboBox1.Items.Add('Mosaic');
ComboBox1.Items.Add('Stripe"');
ComboBox1.Items.Add('Blur');
combobox1.ItemIndex := 0;
//audio effects
ComboBox2.Items.Add('None');
ComboBox2.Items.Add('Chorus');
ComboBox2.Items.Add('Compressor');
ComboBox2.Items.Add('Distortion');
ComboBox2.Items.Add('Echo');
ComboBox2.Items.Add('Flanger');
ComboBox2.Items.Add('Gargle');
ComboBox2.Items.Add('I3DL2Reverb');
ComboBox2.Items.Add('ParamEQ');
ComboBox2.Items.Add('WavesReverb');
combobox2.ItemIndex := 0;
//set volume
EWMedia1.GetCurVolume(volume);
TrackBar1.Position := (100 - volume);

RadioButton12.Checked := True;
end;

procedure TForm1.Button1Click(Sender: TObject);
var width : integer;
    height : integer;
    sample : integer;
    channel : integer;
    duration : Double;
    isvideo : wordbool;
    isaudio : wordbool;
    filename : String;
begin

//open ifo file
Label1.Caption := 'Open file ...';
if OpenDialog1.Execute then
begin
  filename := OpenDialog1.FileName;
  Form1.Refresh;
  ofile := filename;
  EWMedia1.OpenFile(filename);
  EWMedia1.GetFileProperty(filename,duration,isvideo,isaudio,width,height,sample,channel);
  ScrollBar1.Min := 0;
  ScrollBar1.Max := round(duration);
  Label1.Caption := 'Length:' + stotime(duration) + '   ';
  If isvideo Then
    Label1.Caption := Label1.Caption + 'Video is:' + inttostr(width) + '*' + inttostr(height)
  Else
    Label1.Caption := Label1.Caption + 'Video is unavailable.';

  If isaudio Then
    Label1.Caption := Label1.Caption + '   ' + 'Audio is:' + inttostr(sample) + 'HZ  ' + inttostr(channel) + ' Channel'
  Else
    Label1.Caption := Label1.Caption + '   ' + 'Audio is unavailable.';
  infostr := Label1.Caption;
end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
Timer1.Enabled := True;
EWMedia1.Play;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
Timer1.Enabled := True;
EWMedia1.Pause;
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
Timer1.Enabled := False;
EWMedia1.Stop;
end;

procedure TForm1.TrackBar2Change(Sender: TObject);
begin
EWMedia1.SetBalance(TrackBar2.Position);
end;

procedure TForm1.TrackBar1Change(Sender: TObject);
begin
EWMedia1.SetVolume(TrackBar1.Max - TrackBar1.Position)
end;

procedure TForm1.TrackBar3Change(Sender: TObject);
begin
seteq
end;

procedure TForm1.TrackBar4Change(Sender: TObject);
begin
seteq
end;

procedure TForm1.TrackBar5Change(Sender: TObject);
begin
seteq
end;

procedure TForm1.TrackBar6Change(Sender: TObject);
begin
seteq
end;

procedure TForm1.TrackBar7Change(Sender: TObject);
begin
seteq
end;

procedure TForm1.TrackBar8Change(Sender: TObject);
begin
seteq
end;

procedure TForm1.TrackBar9Change(Sender: TObject);
begin
seteq
end;

procedure TForm1.TrackBar10Change(Sender: TObject);
begin
seteq
end;

procedure TForm1.TrackBar11Change(Sender: TObject);
begin
seteq
end;

procedure TForm1.TrackBar12Change(Sender: TObject);
begin
seteq
end;

procedure TForm1.RadioButton3Click(Sender: TObject);
begin
tickertext()
end;

procedure TForm1.RadioButton4Click(Sender: TObject);
begin
tickertext()
end;

procedure TForm1.RadioButton5Click(Sender: TObject);
begin
tickertext()
end;

procedure TForm1.RadioButton6Click(Sender: TObject);
begin
tickertext()
end;

procedure TForm1.RadioButton7Click(Sender: TObject);
begin
tickertext()
end;

procedure TForm1.RadioButton8Click(Sender: TObject);
begin
tickertext()
end;

procedure TForm1.RadioButton9Click(Sender: TObject);
begin
tickertext()
end;

procedure TForm1.RadioButton10Click(Sender: TObject);
begin
tickertext()
end;

procedure TForm1.RadioButton11Click(Sender: TObject);
begin
tickertext()
end;

procedure TForm1.CheckBox1Click(Sender: TObject);
begin
If CheckBox1.Checked = True Then
   EWMedia1.StartTickerSlide(postype, ismove, round(strtofloat(Edit2.text) * 1000))
Else
   EWMedia1.StopTickerSlide;

end;

procedure TForm1.CheckBox2Click(Sender: TObject);
begin
tickertext();
If CheckBox1.Checked = True Then
   EWMedia1.StartTickerSlide(postype, ismove, round(strtofloat(Edit2.text) * 1000))
Else
   EWMedia1.StopTickerSlide;
end;

procedure TForm1.Edit1Change(Sender: TObject);
begin
If (CheckBox1.Checked = True) and  (strtofloat(Edit2.text) > 0) Then
  EWMedia1.StartTickerSlide(postype, ismove, round(strtofloat(Edit2.text) * 1000));
end;

procedure TForm1.ComboBox1Change(Sender: TObject);
var num :Integer;
begin
num := ComboBox1.ItemIndex - 1;
Case num of
    -1:EWMedia1.SetVideoEffect(-1, 0, 0, 0);
    0:EWMedia1.SetVideoEffect(0, 0, 0, 0);
    1:EWMedia1.SetVideoEffect(1, 0, 0, 0);
    2:EWMedia1.SetVideoEffect(2, 3, 0, 0);
    3:EWMedia1.SetVideoEffect(3, 0, 0, 0);
    4:EWMedia1.SetVideoEffect(4, 0, 0, 0);
    5:EWMedia1.SetVideoEffect(5, 255, 10, 0);
    6:EWMedia1.SetVideoEffect(6, 20, 10, 0);
    7:EWMedia1.SetVideoEffect(7, 120, 0, 0);
    8:EWMedia1.SetVideoEffect(8, 15, 0, 0);
    9:EWMedia1.SetVideoEffect(9, 20, 0, 0);
    10:EWMedia1.SetVideoEffect(10, 3, 0, 0);
    11:EWMedia1.SetVideoEffect(11, 35, 25, 0);
    12:EWMedia1.SetVideoEffect(12, 5, 0, 0);
End;
end;

procedure TForm1.ComboBox2Change(Sender: TObject);
var num : Integer;
    curtime : Double;
begin
num := ComboBox2.ItemIndex - 1;
Case num of
  -1:EWMedia1.DisableAudioEffects;
   0:EWMedia1.SetAudChorus(50.0, 10.0, 25.0, 1.1, 1, 16.0, 0);
   1:EWMedia1.SetAudCompressor(0.0, 50.0, 200.0, -20.0, 1.0, 4.0);
   2:EWMedia1.SetAudDistortion(-18.0,15.0, 4143.0, 2400.0, 8000.0);
   3:EWMedia1.SetAudEcho(50.0, 50.0, 500.0, 500.0, 0);
   4:EWMedia1.SetAudFlanger(50.0, 100.0, -50.0, 0.25, 1, 2.0, 2);
   5:EWMedia1.SetAudGargle(20, 0);
   6:EWMedia1.SetAudI3DL2Reverb(-1000, -1000, 0.0, 1.49, 0.83, -2602, 0.007, 200, 0.011, 100.0, 100.0, 5000.0, 2);
   7:EWMedia1.SetAudParamEq(8000.0, 12.0, 12.0);
   8:EWMedia1.SetAudWavesReverb(0.0, 0.0, 1000.0, 0.001);
End;
end;

procedure TForm1.RadioButton1Click(Sender: TObject);
begin
EWMedia1.SetAspectRatioMode(0);
end;

procedure TForm1.RadioButton2Click(Sender: TObject);
begin
EWMedia1.SetAspectRatioMode(1);
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var curtime:real;
    i : Integer;
    j : Integer;
    tmp : integer;
    value : integer;
    value1 : integer;
    max : Integer;
    max1 : Integer;
    jg : Double;
    leftv : integer;
    rightv : integer;
    js : Integer;
    rect : TRect;
    timevalue:double;
    begin
try
  EWMedia1.GetPlayCurTime(timevalue);
  if(timevalue<1.0) then curtime:= 0 else curtime:=timevalue;
  ScrollBar1.Position := round(curtime);
  label1.Caption := infostr + '  Current time:' + stotime(timevalue);
  //DISP DSP
  js := 0;
  //begin draw DSP
  rect.Left := 0;
  rect.Top := 0;
  rect.Right := Image1.Width;
  rect.Bottom := Image1.Height;
  Image1.Canvas.Brush.Color := rgb(0,0,0);
  Image1.Canvas.FillRect(rect);
  jg := Image1.width / 511;
  If RadioButton12.checked Then
  begin
    For i := 0 To 20 do
    begin
      If peaks[i] > 2 Then
      begin
         peaks[i] := peaks[i] - 2;
         If peaks[i] < 2 Then
            peaks[i] := 2;
      end;
    end;

  //image1 spectrum
  i := 0;
  max := 0;
  while(i<511) do
  Begin
    EWMedia1.GetDSPValue(i,tmp);
    If (tmp > max) Then max := tmp;

    if (i mod 26) = 0 then
    begin
      value := max;
      if(i=0) then rect.left := 0 else rect.Left := trunc(jg*i);
      rect.Top := Image1.Height - value;
      if(i=0) then rect.Right := 8 else rect.Right := trunc(jg * i+8);
      rect.Bottom := Image1.Height;
      Image1.Canvas.Brush.Color := rgb(0,255,0);//0,166,81
      Image1.Canvas.FillRect(rect);
      If value > peaks[js] Then
      begin
        peaks[js] := value;
      end;
      max := 0;
      tmp := 0;
      js := js + 1;
    end;
    i := i+1;
  end;
  //draw peaks
  js := 0;
  i:=0;
  while(js<20) do
  begin
    rect.Left := trunc(jg*js*26);
    rect.Top := Image1.Height - (peaks[js] + 2);
    rect.Right := trunc(jg * js*26+8);
    rect.Bottom := Image1.Height - peaks[js];
    Image1.Canvas.Brush.Color := rgb(109,207,246);
    Image1.Canvas.FillRect(rect);
    js := js+1;
  end;
end;
 
If RadioButton13.checked Then
begin
max := 0;
max1 := 0;
//For i = 0 To 511 Step 10
Image1.Canvas.MoveTo(0,trunc(Image1.height/2));
i:=1;
while(i<511) do
begin
  //tmp = EWMedia1.GetDSPValue(i)
  Image1.Canvas.Pen.Color := rgb(0,255,0);
  EWMedia1.GetDSPValue(i,value);
  EWMedia1.GetDSPValue(i + 10,value1);
  if(i=0) then Image1.Canvas.LineTo(trunc(jg * i), value);
  Image1.Canvas.MoveTo(trunc(jg * i), value);
  Image1.Canvas.LineTo(trunc(jg * (i + 10)), value1);
  //Picture2.Line (jg * i, value)-(jg * (i + 10), value1), RGB(0, 255, 0)
  i := i + 10;
end;
End;
except
end;

end;

procedure TForm1.ScrollBar1Scroll(Sender: TObject; ScrollCode: TScrollCode;
  var ScrollPos: Integer);
begin
EWMedia1.SeekToPos(ScrollBar1.Position);
end;

procedure TForm1.Button5Click(Sender: TObject);
var filename :string;
begin
if SaveDialog1.Execute then
begin
  filename := SaveDialog1.FileName;
  EWMedia1.CaptureImage(filename);
end;
end;

procedure TForm1.FormShow(Sender: TObject);
var rect:trect;
begin
rect.Left := 0;
rect.Top := 0;
rect.Right := IMAGE1.Width;
rect.Bottom := IMAGE1.Height;
IMAGE1.Canvas.Brush.Color := rgb(0,0,0);
IMAGE1.Canvas.FillRect(rect);
end;

procedure TForm1.RadioButton12Click(Sender: TObject);
begin
EWMedia1.SetPlayDSPDisplay(0, 0, IMAGE1.Height);
end;

procedure TForm1.RadioButton13Click(Sender: TObject);
begin
EWMedia1.SetPlayDSPDisplay(1, 0, IMAGE1.height);
end;

procedure TForm1.ScrollBar2Change(Sender: TObject);
begin
  EWMedia1.SetPlayRate(scrollbar2.Position/100)
end;

procedure TForm1.TrackBar13Change(Sender: TObject);
var value:real;
begin
value := (2000-trackbar13.Position)/10;
if(value<0.1) then value := 0.1;
EWmedia1.SetAudPitch(value);
label33.Caption := format('%.1f',[value])+'%';
end;

procedure TForm1.TrackBar14Change(Sender: TObject);
var value:real;
begin
value := -trackbar14.Position/10;
EWMedia1.SetAudTempo(value);
label34.Caption :=  format('%.1f',[100+value])+'%';

end;

end.



Sekian Dan Terima Kasih......

Posting Komentar

Please Select Embedded Mode To Show The Comment System.*

Lebih baru Lebih lama