Delphi - alguna ayuda con un reprod de musica

 
Vista:
sin imagen de perfil

alguna ayuda con un reprod de musica

Publicado por Federico (39 intervenciones) el 10/11/2014 16:57:41
Hola gente necesito alguna ayuda para arreglar un reproductor de música que debo hacer.
La parte que debo arreglar es la de reproducción aleatoria continua y repetitiva, funciona cada uno pero no como tendría que ser. En algunos casos me aparece algo como error MCI y no se si esta bien como obtener el nombre del archivo en un Tlistbox(lbxz1)
cualquier ayuda se agradece.

el código es:



unit Unit5;

interface

uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.StdCtrls,
Vcl.ComCtrls, Vcl.MPlayer, Vcl.Menus,MMSystem;

type
TForm5 = class(TForm)
mp: TMediaPlayer;
progreso: TTrackBar;
tbvol: TTrackBar;
lbx1: TListBox;
OpenDialog1: TOpenDialog;
timer: TTimer;
MainMenu1: TMainMenu;
Archivo1: TMenuItem;
Abrir1: TMenuItem;
GuardarPlaylist1: TMenuItem;
CargarPlaylist1: TMenuItem;
Salir2: TMenuItem;
lbllen1: TLabel;
lbllen2: TLabel;
lbln: TLabel;
lblseek: TLabel;
SaveDialog1: TSaveDialog;
OpenDialog2: TOpenDialog;
lblpos1: TLabel;
lblpos2: TLabel;
tvol: TLabel;
Button1: TButton;
Rg: TRadioGroup;
procedure Salir2Click(Sender: TObject);
procedure Abrir1Click(Sender: TObject);
procedure timerTimer(Sender: TObject);
procedure GuardarPlaylist1Click(Sender: TObject);
procedure CargarPlaylist1Click(Sender: TObject);
procedure tbvolChange(Sender: TObject);
procedure lbx1DblClick(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure RgClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
// procedure CheckIfOpen;


end;

var
Form5: TForm5;
i,il,itel:integer;
s:String;
r:integer;
implementation

{$R *.dfm}


procedure TForm5.Abrir1Click(Sender: TObject);
var
slied,sname : string;
ip : integer;
begin
opendialog1.Execute;
slied := opendialog1.FileName;
mp.FileName:= slied;
mp.Open;
itel := mp.TrackLength[1];
timer.Enabled:=true;
lbllen1.Caption := IntToStr(((trunc(itel/1000))div 60)) + ':';
lbllen2.caption := IntToStr((trunc(itel/1000))mod 60);

if length(IntToStr((trunc(itel/1000))mod 60)) <> 2
then
lbllen2.Caption := '0' + IntToStr((trunc(itel/1000))mod 60);

sname := slied;

repeat
ip := pos('\',sname);
Delete(sname,1,ip);
until (ip =0);

lbln.caption := sname;

with progreso do
progreso.Max:=mp.Length;

lbx1.Items.Add(mp.FileName);
end;

procedure TForm5.Button1Click(Sender: TObject);
begin
lbx1.Clear;
end;

procedure TForm5.CargarPlaylist1Click(Sender: TObject);
begin
opendialog2.Execute;
lbx1.Items.LoadFromFile(opendialog2.FileName);
timer.Enabled := true;
lbx1.ItemIndex := 0;
i := lbx1.itemindex;
mp.FileName := lbx1.Items.Strings[i];
mp.Open;
end;


procedure TForm5.GuardarPlaylist1Click(Sender: TObject);
begin
savedialog1.Execute;
lbx1.Items.SaveToFile(savedialog1.FileName + '.amp');
end;

procedure TForm5.Salir2Click(Sender: TObject);
begin
Close;
end;

procedure TForm5.timerTimer(Sender: TObject);
begin
progreso.Position := mp.Position;
if progreso.Max>0 then
progreso.Position:=mp.Position;
itel := mp.Position;
lblpos1.Caption := IntToStr(((trunc(itel/1000))div 60)) + ':';
lblpos2.caption := IntToStr((trunc(itel/1000))mod 60);
if length(IntToStr((trunc(itel/1000))mod 60)) <> 2
then
lblpos2.Caption := '0' + IntToStr((trunc(itel/1000))mod 60);

if lblseek.Caption = 'Position:'
then progreso.Position := mp.Position;

if mp.Position = mp.TrackLength[1]
then begin
lbx1.ItemIndex := lbx1.ItemIndex + 1;
i := lbx1.ItemIndex;
mp.FileName := lbx1.Items.Strings[i];
mp.Open;
mp.Play;
s := mp.FileName;
repeat
il := pos('\',s);
Delete(s,1,il);
until (il =0);
lbln.Caption := s;

itel := mp.TrackLength[1];
lbllen1.Caption := IntToStr(((trunc(itel/1000))div 60)) + ':';
lbllen2.caption := IntToStr((trunc(itel/1000))mod 60);



end;
progreso.Max := mp.TrackLength[1];
end;

procedure TForm5.tbvolChange(Sender: TObject);
begin
waveOutSetVolume(WAVE_MAPPER,(tbvol.position-63488)*-1 shl 16 +(tbvol.position-63488)*-1);
end;

procedure TForm5.lbx1DblClick(Sender: TObject);
begin
timer.Enabled := true;
i := lbx1.ItemIndex;
mp.FileName := lbx1.Items.Strings[i];
mp.Open;
s := mp.FileName;
repeat
il := pos('\',s);
Delete(s,1,il);
until (il =0);
lbln.Caption := s;

itel := mp.TrackLength[1];
lbllen1.Caption := IntToStr(((trunc(itel/1000))div 60)) + ':';
lbllen2.caption := IntToStr((trunc(itel/1000))mod 60);
mp.Play;
end;

procedure TForm5.RgClick(Sender: TObject);
begin
case rg.ItemIndex of
0: begin
timer.Enabled := False; //continua
mp.Stop;
mp.Close;
lbx1.ItemIndex := lbx1.ItemIndex+1;
mp.FileName := lbx1.Items[Lbx1.ItemIndex];
mp.Open;
progreso.Max := mp.TrackLength[0];
mp.Play;
timer.Enabled:=True;
lbln.Caption:= lbx1.Items.Strings[lbx1.ItemIndex];
end;
1: begin
timer.Enabled := False; //aleatoria
mp.Stop;
mp.Close;
r := Random (lbx1.Items.Count);
lbx1.ItemIndex := r;
mp.FileName := lbx1.Items[Lbx1.ItemIndex];
mp.Open;
progreso.Max := mp.TrackLength[0];
mp.Play;
timer.Enabled := True;
lbln.Caption := lbx1.Items.Strings[lbx1.ItemIndex];
end;
2: begin
progreso.Max := mp.Length; //repetitiva
timer.Enabled := true;
mp.EnabledButtons := [tmpbtntype.btPause,tmpbtntype.btStop,tmpbtntype.btPlay];
mp.Play;
lbln.caption := extractfilename(mp.FileName)+' - '+extractfilename(mp.FileName);
end;
end;
end;

end.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder