Professional Documents
Culture Documents
p: MCI_DGV_SETAUDIO_PARMS;
begin
p.dwCallback := 0;
p.dwItem := MCI_DGV_SETAUDIO_VOLUME;
p.dwValue := Volume;
p.dwOver := 0;
p.lpstrAlgorithm := nil;
p.lpstrQuality := nil;
mciSendCommand(MP.DeviceID, MCI_SETAUDIO, MCI_DGV_SETAUDIO_VALUE or MCI_DGV_SE
TAUDIO_ITEM, Cardinal(@p)) ;
end;
function MPGetVolume(MP: TMediaPlayer): Integer;
var
p: MCI_STATUS_PARMS;
begin
p.dwCallback := 0;
p.dwItem := MCI_DGV_STATUS_VOLUME;
mciSendCommand(MP.DeviceID, MCI_STATUS, MCI_STATUS_ITEM, Cardinal(@p)) ;
Result := p.dwReturn;
end;
// ----------------------------------------------------------------------------// Drag & drop file from explorer
procedure TForm1.WMDROPFILES(var msg: TWMDropFiles);
var
i, fileCount: integer;
namafile: array[0..MAX_PATH] of char;
begin
fileCount:=DragQueryFile(msg.Drop, $FFFFFFFF, namafile, MAX_PATH);
for i := 0 to fileCount - 1 do begin
DragQueryFile(msg.Drop, i, namafile, MAX_PATH);
TambahListLagu(namafile);
end;
DragFinish(msg.Drop);
end;
procedure TForm1.CreateWnd;
begin
inherited;
DragAcceptFiles(Handle, True);
end;
procedure TForm1.DestroyWnd;
begin
DragAcceptFiles(WindowHandle, false);
inherited;
end;
// ----------------------------------------------------------------------------function TForm1.FormatWaktu(milidetik: integer): string;
var
menit, detik: integer;
begin
detik := milidetik div 1000;
menit := detik div 60;
detik := detik - (menit*60);
Result := IntToStr(menit) + ':' + IntToStr(detik);
Result := Format('%.*d:%.*d', [2, menit, 2, detik]);
end;
lvPlaylist.ClearSelection;
lvPlaylist.Items[idxLagu].Selected := True;
try
mplayer.Open;
lvPlaylist.Refresh;
lbJudul.Left := pnJudul.Left + pnJudul.Width;
ScrollBar1.Max := mplayer.Length;
tmJudul.Enabled := True;
tmProgress.Enabled := True;
Sleep(500);
mplayer.Play;
btPlay.Caption := 'Pause';
Result := True
except
Sleep(1000);
btNext.Click;
end;
end;
procedure TForm1.LaguBerikut;
begin
if idxLagu < lvPlaylist.Items.Count-1 then
idxLagu := idxLagu + 1
else
idxLagu := 0;
MainkanLagu;
end;
procedure TForm1.SimpanPlaylist(namafile: string);
var
f: textfile;
i: integer;
begin
AssignFile(f, namafile);
Rewrite(f);
for i:=0 to lvPlaylist.Items.Count-1 do
Writeln(f, lvPlaylist.Items[i].Caption);
CloseFile(f);
end;
procedure TForm1.LoadPlaylist(namafile: string);
var
f: textfile;
txt: string;
begin
if not FileExists(namafile) then Exit;
lvPlaylist.Items.Clear;
AssignFile(f, namafile);
Reset(f);
while not EOF(f) do begin
Readln(f, txt);
TambahListLagu(txt);
end;
CloseFile(f);
end;
procedure TForm1.LaguSebelum;
begin
if idxLagu <= 0 then
idxLagu := lvPlaylist.Items.Count-1
else
idxLagu := idxLagu - 1;
MainkanLagu;
end;
procedure TForm1.btOpenClick(Sender: TObject);
var
i: integer;
namafile, errorMsg: string;
jumError: integer;
begin
OpenDialog1.Title := 'Tambahkan lagu';
OpenDialog1.Filter := 'Mp3 Files|*.mp3';
OpenDialog1.DefaultExt := '.mp3';
if OpenDialog1.Execute then begin
errorMsg := '';
jumError := 0;
for i:=0 to OpenDialog1.Files.Count-1 do begin
namafile := OpenDialog1.Files[i];
if not TambahListLagu(namafile) then begin
Inc(jumError);
errorMsg := errorMsg + #13 + namafile;
end;
end;
if jumError > 0 then begin
errorMsg := IntToStr(jumError)+ ' file tidak bisa ditambahkan :' +errorMsg
;
MessageDlg(errorMsg, mtError, [mbOk], 0);
end;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
// Set property default saat aplikasi dijalankan
with lvPlaylist do begin
DragMode := dmAutomatic;
RowSelect := True;
MultiSelect := True;
ViewStyle := vsReport;
end;
with mplayer do begin
TimeFormat := tfMilliseconds;
Notify := True;
end;
with barVolume do begin
Min := 0;
Max := 1000;
Position := MPGetVolume(mplayer);
end;
lbJudul.Caption := '';
tmJudul.Enabled := False;
pnWaktu.Caption := '00:00';
tmProgress.Enabled := False;
idxLagu := 0;
// Load list lagu sebelumnya jika ada
LoadPlaylist(ExtractFilePath(Application.ExeName) + 'listLagu.lst');
end;
begin
mplayer.Position := ScrollBar1.Position;
mplayer.Play;
btPlay.Caption := 'Pause';
end;
procedure TForm1.btNextClick(Sender: TObject);
begin
LaguBerikut;
end;
procedure TForm1.Hapus1Click(Sender: TObject);
begin
lvPlaylist.DeleteSelected;
AturIndexLagu;
end;
procedure TForm1.ambahFile1Click(Sender: TObject);
begin
btOpen.Click;
end;
procedure TForm1.barVolumeChange(Sender: TObject);
begin
MPSetVolume(mplayer, barVolume.Position) ;
end;
procedure TForm1.btPrevClick(Sender: TObject);
begin
LaguSebelum;
end;
procedure TForm1.mplayerNotify(Sender: TObject);
begin
if mplayer.Mode = mpPlaying then begin
lbJudul.Caption := StringReplace(lbJudul.Caption, ' (Paused)', '', [rfIgnore
Case]);
lbJudul.Font.Color := clLime;
end;
mplayer.Notify := True;
end;
{ Mengurutkan item listview
sumber: http://delphi.about.com/od/vclusing/a/arrangelistview.htm }
procedure TForm1.lvPlaylistDragDrop(Sender, Source: TObject; X,
Y: Integer);
var
currentItem, nextItem, dragItem, dropItem : TListItem;
begin
if Sender = Source then
begin
with TListView(Sender) do
begin
dropItem := GetItemAt(X, Y) ;
currentItem := Selected;
while currentItem <> nil do
begin
nextItem := GetNextItem(currentItem, SdAll, [IsSelected]) ;
if Assigned(dropItem) then
dragItem := Items.Insert(dropItem.Index)
else
dragItem := Items.Add;
dragItem.Assign(currentItem) ;
currentItem.Free;
currentItem := nextItem;
end;
end;
AturIndexLagu;
end;
end;
procedure TForm1.lvPlaylistDragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
begin
Accept := Sender = lvPlaylist;
end;
// ----------------------------------------------------------------------------procedure TForm1.SimpanPlaylist1Click(Sender: TObject);
begin
btSimpanpls.Click;
end;
procedure TForm1.LoadPlaylist1Click(Sender: TObject);
begin
btLoadpls.Click;
end;
procedure TForm1.btSimpanplsClick(Sender: TObject);
begin
if lvPlaylist.Items.Count < 1 then begin
MessageDlg('Playlist masih kosong!', mtInformation, [mbOk], 0);
Exit;
end;
SaveDialog1.Title := 'Simpan playlist';
SaveDialog1.Filter := 'Playlist Files|*.lst';
SaveDialog1.DefaultExt := '.lst';
if SaveDialog1.Execute then
SimpanPlaylist(SaveDialog1.FileName);
end;
procedure TForm1.btLoadplsClick(Sender: TObject);
begin
OpenDialog1.Title := 'Load playlist';
OpenDialog1.Filter := 'Playlist Files|*.lst';
OpenDialog1.DefaultExt := '.lst';
if OpenDialog1.Execute then
LoadPlaylist(OpenDialog1.FileName);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
// Simpan list lagu untuk di-load kembali saat app dijalankan
SimpanPlaylist( ExtractFilePath(Application.ExeName) + 'listLagu.lst' );
end;
procedure TForm1.lvPlaylistAdvancedCustomDrawItem(Sender: TCustomListView;
Item: TListItem; State: TCustomDrawState; Stage: TCustomDrawStage;
var DefaultDraw: Boolean);
begin