Saturday, May 7, 2011

Membuat Playlist Dengan Delphi

//Membuat Play List dengan Delphi
{
Created By : Zephio
Contact :  zephio@myspace.com
URL : http://amateur-guide.blogspot.com
Copyright © 2011, Zephio.
}
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, MPlayer;

type
  TForm1 = class(TForm)
  //Component yg digunakan------------------------------------------------------>
    ListBox1: TListBox;
    Button1: TButton;
    OD: TOpenDialog;
    Button2: TButton;
    Button3: TButton;
    SD: TSaveDialog;
    MP: TMediaPlayer;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure ListBox1DblClick(Sender: TObject);
    procedure FormActivate(Sender: TObject);
  private
    { Private declarations }
  public
    //Export To Playlist-------------------------------------------------------->
    function ETPL(S : String) : String;
    { Public declarations }
  end;

var
  Form1: TForm1;
Const
   //Default Title
   DS : String = 'ZS-Play List v1.0';
implementation

{$R *.dfm}

//Export To Playlist------------------------------------------------------------>
function TForm1.ETPL(S : String) : String;
var
   I : Integer;
   SL : TStringList; //Temporary String----------------------------------------->
begin
   SL := TStringList.Create;
   SL.Add('<Head>');
   Sl.Add('<Author>Zephio</Author>');
   SL.Add('<Title>Zephio Soft Play List v1.0</Title>');
   SL.Add(' <Body>');
   SL.Add('  <Total>'+IntToHex(ListBox1.Count, 4)+'</Total>');
for I := 0 to ListBox1.Count  - 1 do
   SL.Add('   <Path="'+ListBox1.Items[I]+'"/>');
   SL.Add(' </body>');
   SL.Add('</Head>');
   SL.SaveToFile(S);
   SL.Free;
end;

//Load Playlist----------------------------------------------------------------->
procedure TForm1.Button1Click(Sender: TObject);
const
   AB : array[0..6] of Char='<Path="';// array 0 - 6 of char = 7---------------->
   AE : array[0..2] of Char='"/>';// array 0 - 2 of char = 3-------------------->
var
   I : Integer;
   SL : TStringList;
begin
   OD.DefaultExt := '*.zs';
   OD.Filter := 'ZS Files|*.zs';
   SL := TStringList.Create;
if not OD.Execute then
   Exit;
   ListBox1.Clear;
   SL.LoadFromFile(OD.FileName);
//Jika tidak ditemukan kata dibawah ini dalam playlist,
// maka applikasi akan menolak playlist tsb
if (SL.Strings[0] <> '<Head>') and
   (SL.Strings[1] <> '<Author>Zephio</Author>') and
   (SL.Strings[2] <> '<Title>Zephio Soft Play List v1.0</Title>') and
   (SL.Strings[3] <> ' <Body>') then
   Exit
else
   Caption := DS+' - [ '+Copy(SL.Strings[1], 9, Length(SL.Strings[1]) - 17)+' ]'+' '+IntToStr(Length(AB))+' '+IntToStr(Length(AE));
{
I = 5 trhitung dari:
1. <Head>
2. <Author>Zephio</Author>
3. <Title>Zephio Soft Play List v1.0</Title>
4. <Body>
5. mengambil Path yg pertama
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SL.Count - 3 = Total Baris pd playlist tsb dikurangi
3. </body>
2. </Head>
1. '' dari I = 0 - Total Baris
}
for I := 5 to SL.Count - 3 do
   ListBox1.Items.Add(Copy(SL.Strings[I], 11, Length(SL.Strings[I]) - 13));
   SL.Free;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
   I : Integer;
begin
   OD.DefaultExt := '*.mp3';
   OD.Filter := 'MP3 Files|*.mp3';
if not OD.Execute then
   Exit;
   ListBox1.Clear;
//I = 0 - Total File pada Open Dialog------------------------------------------->
// atau juga for I := 1 to Total File pada Open Dialog-------------------------->
for I := 0 to OD.Files.Count - 1 do
   ListBox1.Items.Add(OD.Files[I]);
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
if not SD.Execute then
   Exit;
//Export Playlist dari Temporay ke File----------------------------------------->
   ETPL(SD.FileName);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
   Caption := 'ZS-2011';
end;

procedure TForm1.ListBox1DblClick(Sender: TObject);
begin
   MP.FileName := ListBox1.Items[ListBox1.ItemIndex];
   MP.Open;
end;

procedure TForm1.FormActivate(Sender: TObject);
begin
   Caption := DS;
   Application.Title := DS;
end;

end.

{ untuk versi Console Apps cuma load playlist'e saja }

program ZS;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  Classes;

const
   AB : array[0..6] of Char='<Path="';
   AE : array[0..2] of Char='"/>';
var
   I : Integer;
   SL : TStringList;
begin
   SL := TStringList.Create;
if not FileExists('ZS.zs') then
   Exit
else
   SL.LoadFromFile('ZS.zs');//Nama file'e
if (SL.Strings[0] <> '<Head>') and
   (SL.Strings[1] <> '<Author>Zephio</Author>') and
   (SL.Strings[2] <> '<Title>Zephio Soft Play List v1.0</Title>') and
   (SL.Strings[3] <> ' <Body>') then
   Exit
else
   WriteLn('Author : '+Copy(SL.Strings[1], 9, Length(SL.Strings[1]) - 17));
   WriteLn('Title  : '+Copy(SL.Strings[2], 8, Length(SL.Strings[2]) - 15));
   WriteLn('=========================================================================');
for I := 5 to SL.Count - 3 do
   WriteLn(Copy(SL.Strings[I], 11, Length(SL.Strings[I]) - 13));
While true do
   Sleep(1000);
   SL.Free;
end.



Download Source Code : Link
MH : Media Fire
FS : 259KB

5 comments:

  1. desain formnya mana??

    ReplyDelete
  2. aku memang tidak upload projectnya, tp aku rasa mudah dimengerti kawan.

    ReplyDelete
  3. iya ga ada form nya nih,,jd ga jelas,,sukar tuk di pahami..

    ReplyDelete
  4. o ma'af jk sulit dimengerti lain waktu aku upload SC'e.

    ReplyDelete
  5. sdh aku upload smg membantu, aku sesuaikan dgn tutorial diatas tidak menambah/mengurangi. playlist tsb bs diadaptasikan dgn bass.dll, fmod, dsm etc. jk ingin membuat playlist *.m3u tgl menambahkan SC pd Pilih Nomor Genap.

    e.g :
    1. Music1
    2. D:\Music1.mp3
    3. Music2
    4. D:\Music2.mp3

    maka apa y istilah'e???... hehehe :)
    anggap sj Engine akan Mensortir baris nomor ganjil spt d bwh ini.

    D:\Music1.mp3
    D:\Music2.mp3

    jk msh bingung PM aku @http://facebook/zephio85

    ReplyDelete