Ir para conteúdo
Fórum Script Brasil
  • 0

(Resolvido) Lista de musicas


António44

Pergunta

Meus amigos preciso de ajuda no seguinte.

Com o codigo que já estou usando como faço um play na lista,para iniçiar na faixa 1 ate ao final da lista.

procedure TForm1.Button5Click(Sender: TObject);
begin
if listbox1.itemindex <0 then
showmessage('lista vazia...selecione musica ')else
begin
  mciSendString('Close MM', abc, 0, 0); //Close audio
 fname := listbox1.Items.strings[listbox1.itemindex]; //Get what was selected
 abc3 := GetShortName(fname); //Change filename to short file name
 abc2 := PChar('Open ' + abc3 + ' Alias MM'); //Open file code
 mciSendString(abc2, abc, 0, 0); //Open the file to play
 mciSendString('Play MM', abc, 0, 0); //Play the file
end;
end;

Alguma ideia ai, é que assim só reproduz uma a uma ou seja,a seleccionada  e não reproduz a lista toda mesmo que seleccione todas as faixas da lista.

Obrigada

Link para o comentário
Compartilhar em outros sites

Posts Recomendados

  • 0

crie um novo projeto e crie novamente esse form do zero com esse código

não mude nada ... compile e execute .... depois faça as suas modificações

OBS: é só copiar e colar no seu form e acrescentar os componentes e fazer os links dos componentes

Outra coisa, foi compilado em delphi 7

o timer voce deixa false antes de exeutar o programa

Timer1.Enabled := false;
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls,MMSystem, Forms, Dialogs,
  StdCtrls, MPlayer, ComCtrls, ExtCtrls, Gauges;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    Button5: TButton;
    Button6: TButton;
    Button7: TButton;
    Button8: TButton;
    ListBox1: TListBox;
    TrackBar1: TTrackBar;
    Button9: TButton;
    OpenDialog1: TOpenDialog;
    SaveDialog1: TSaveDialog;
    Timer1: TTimer;
    Gauge1: TGauge;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button8Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure ListBox1Click(Sender: TObject);
    procedure TrackBar1Change(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  fname : string; //FileName
  i : integer = 0;

implementation


{$R *.DFM}

procedure TForm1.TrackBar1Change(Sender: TObject);
var
   Count , i : longint;  // 4369
begin
   Count := waveOutGetNumDevs;
   for i := 0 to Count do
     begin
        waveOutSetVolume(i,longint(TrackBar1.position*1369)*65536+longint(TrackBar1.position*1369));
     end;
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
 If opendialog1.Execute = True Then  //Shows open dialog
 begin
   fname := opendialog1.filename; //Makes fname the filename selected (If one was selected)
   listbox1.items.add(opendialog1.filename); //Add it to the list box
 end;
end;

procedure OpenMP3(FileName: String);
begin
  mciSendString(PChar('open "' + FileName + '" alias mp wait'), nil, 0, 0);
end;

procedure PlayMP3;
begin
  mciSendString(PChar('play mp'), nil, 0, 0);
end;

procedure StopMP3;
begin
  mciSendString(PChar('stop mp'), nil, 0, 0);
end;

procedure PauseMP3;
begin
  mciSendString(PChar('pause mp'), nil, 0, 0);
end;

procedure CloseMP3;
begin
  mciSendString(PChar('close mp'), nil, 0, 0);
end;

procedure ForwardMP3(ToPlace: LongInt = 1);
var
  TmpStr: PChar;
begin
  GetMem(TmpStr, 128);

  mciSendString(PChar('set mp time format milliSeconds'), nil, 0, 0);
  mciSendString(PChar('status mp position wait'), TmpStr, 128, 0);
  mciSendString(PChar('play mp from ' + IntToStr(StrToInt(TmpStr) + ToPlace)),
nil, 0, 0);
  mciSendString(PChar('set mp time format tmsf'), nil, 0, 0);

  FreeMem(TmpStr);
end;

procedure RewindMP3(ToPlace: LongInt = 1);
var
  TmpStr: PChar;
begin
  GetMem(TmpStr, 128);

  mciSendString(PChar('set mp time format milliSeconds'), nil, 0, 0);
  mciSendString(PChar('status mp position wait'), TmpStr, 128, 0);
  mciSendString(PChar('play mp from ' + IntToStr(StrToInt(TmpStr) - ToPlace)),
nil, 0, 0);
  mciSendString(PChar('set mp time format tmsf'), nil, 0, 0);

  FreeMem(TmpStr);
end;

function GetMP3Len: LongInt;
var
  TmpStr: PChar;
begin
  GetMem(TmpStr, 128);

  mciSendString(PChar('set mp time format milliSeconds'), nil, 0, 0);
  mciSendString(PChar('status mp length wait'), TmpStr, 128, 0);
  mciSendString(PChar('set mp time format tmsf'), nil, 0, 0);

  Result := StrToInt(TmpStr);
  FreeMem(TmpStr);
end;

function GetMP3Pos: LongInt;
var
  TmpStr: PChar;
begin
  GetMem(TmpStr, 128);

  mciSendString(PChar('set mp time format milliSeconds'), nil, 0, 0);
  mciSendString(PChar('status mp position wait'), TmpStr, 128, 0);
  mciSendString(PChar('set mp time format tmsf'), nil, 0, 0);

  Result := StrToInt(TmpStr);
  FreeMem(TmpStr);
end;

procedure SetMP3Pos(ToPlace: LongInt = 1);
begin
  mciSendString(PChar('set mp time format milliSeconds'), nil, 0, 0);
  mciSendString(PChar('play mp from ' + IntToStr(ToPlace)), nil, 0, 0);
  mciSendString(PChar('set mp time format tmsf'), nil, 0, 0);
end;


procedure TForm1.Button2Click(Sender: TObject);
begin
   OpenMP3(fname);
end;

procedure TForm1.Button8Click(Sender: TObject);
begin
   OpenMP3(fname);
   Gauge1.MaxValue := GetMP3Len;
   PlayMP3;
   Timer1.Enabled := true;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin

   Gauge1.Refresh;

  if Gauge1.MaxValue <> 0 then
     Gauge1.Progress := GetMP3Pos;

  if  Gauge1.Progress = Gauge1.MaxValue then
      begin
         Gauge1.Progress := 0;
         CloseMP3;
         fname :=  ListBox1.Items.Strings[listbox1.itemindex+1];
         OpenMP3(fname);
         PlayMP3;
         TrackBar1Change(sender);
      end;
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
   StopMP3;
   Timer1.Enabled := false;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
   PauseMP3;
   Timer1.Enabled := false;
end;

procedure TForm1.Button5Click(Sender: TObject);
begin
   RewindMP3;
   Gauge1.Progress := 0;
end;

procedure TForm1.Button6Click(Sender: TObject);
begin
   ForwardMP3;
end;

procedure TForm1.ListBox1Click(Sender: TObject);
begin
   StopMP3;
   CloseMP3;
   fname :=  ListBox1.Items.Strings[listbox1.itemindex];
   Gauge1.Progress := 0;
   Timer1.Enabled := false;
end;



end.

abraço

Link para o comentário
Compartilhar em outros sites

  • 0

amigo, era só corrigir isso no Timer

procedure TForm1.Timer1Timer(Sender: TObject);
begin

   Gauge1.Refresh;

  if Gauge1.MaxValue <> 0 then
     Gauge1.Progress := GetMP3Pos;

  if  Gauge1.Progress = Gauge1.MaxValue then
      begin
         Gauge1.Progress := 0;
         CloseMP3;

         if  listbox1.itemindex+1 <= ListBox1.Items.Count then
             begin
                fname :=  ListBox1.Items.Strings[listbox1.itemindex+1];
                // mostrar qual musica da lista esta tocando
                ListBox1.ItemIndex := listbox1.itemindex+1;
             end
         else
             Timer1.Enabled := false;

         OpenMP3(fname);
         PlayMP3;
         TrackBar1Change(sender);
      end;
end;

 basta fazer essa mudança nessas procedures para rodar no Delphi 3

procedure ForwardMP3; //(ToPlace: LongInt = 1);
var
  TmpStr: PChar;
begin
  GetMem(TmpStr, 128);

  mciSendString(PChar('set mp time format milliSeconds'), nil, 0, 0);
  mciSendString(PChar('status mp position wait'), TmpStr, 128, 0);
  mciSendString(PChar('play mp from ' + IntToStr(StrToInt(TmpStr) + 1 )),
nil, 0, 0);
  mciSendString(PChar('set mp time format tmsf'), nil, 0, 0);

  FreeMem(TmpStr);
end;

procedure RewindMP3; //(ToPlace: LongInt = 1);
var
  TmpStr: PChar;
begin
  GetMem(TmpStr, 128);

  mciSendString(PChar('set mp time format milliSeconds'), nil, 0, 0);
  mciSendString(PChar('status mp position wait'), TmpStr, 128, 0);
  mciSendString(PChar('play mp from ' + IntToStr(StrToInt(TmpStr) - 1 )),
nil, 0, 0);
  mciSendString(PChar('set mp time format tmsf'), nil, 0, 0);

  FreeMem(TmpStr);
end;

----------------------------------------------------------------------
procedure SetMP3Pos; //(ToPlace: LongInt = 1);
begin
  mciSendString(PChar('set mp time format milliSeconds'), nil, 0, 0);
  mciSendString(PChar('play mp from ' + IntToStr(1)), nil, 0, 0);
  mciSendString(PChar('set mp time format tmsf'), nil, 0, 0);
end;

OBS: onde estava a variavel ToPlace no código coloque 1

abraço

Link para o comentário
Compartilhar em outros sites

  • 0

Acrescentei 2 linhas no timer1 e agora não da erro e quando chega na ultima volta para a 1º  a lista ta funcionando bem o que eu queria agora era, tendo a lista carregada com várias faixas tenha esta opção de tocar todas e outra para só tocar a faixa seleccionada.

procedure TForm1.Timer1Timer(Sender: TObject);
begin

   Gauge1.Refresh;

  if Gauge1.MaxValue <> 0 then
     Gauge1.Progress := GetMP3Pos;

  if  Gauge1.Progress = Gauge1.MaxValue then
      begin
         Gauge1.Progress := 0;
         if ListBox1.ItemIndex >= ListBox1.items.Count -1 then exit;//acrescentei aqui esta linha
         CloseMP3;//Mudei aqui esta linha
          fname :=  ListBox1.Items.Strings[listbox1.itemindex+1];
         ListBox1.ItemIndex := ListBox1.ItemIndex + 1;//acrescentei aqui esta linha
        
  
         OpenMP3(fname);
         PlayMP3;
         TrackBar1Change(sender);
 end;
 end;

Abraço

Link para o comentário
Compartilhar em outros sites

  • 0

é só fazer essa modificação

procedure TForm1.ListBox1Click(Sender: TObject);
begin
   StopMP3;
   CloseMP3;
   fname :=  ListBox1.Items.Strings[listbox1.itemindex];
   Gauge1.Progress := 0;
   Timer1.Enabled := false;
   Button8.Click;
end;

basta clicar na musica que voce quer ouvir

abraço

Link para o comentário
Compartilhar em outros sites

  • 0

eu já coloquei isso ... não viu ?

procedure TForm1.Timer1Timer(Sender: TObject);
begin

   Gauge1.Refresh;

  if Gauge1.MaxValue <> 0 then
     Gauge1.Progress := GetMP3Pos;

  if  Gauge1.Progress = Gauge1.MaxValue then
      begin
         Gauge1.Progress := 0;
         CloseMP3;

         if  listbox1.itemindex+1 <= ListBox1.Items.Count then
             begin
                fname :=  ListBox1.Items.Strings[listbox1.itemindex+1];
                // mostrar qual musica da lista esta tocando
                ListBox1.ItemIndex := listbox1.itemindex+1;
             end
         else
             Timer1.Enabled := false;

         OpenMP3(fname);
         PlayMP3;
         TrackBar1Change(sender);
      end;
end;

abraço

 

Link para o comentário
Compartilhar em outros sites

  • 0

E possivel a medida que vai passando as faixas mudar tb a selecção auto no listbox?

A faixa muda mas selecão não muda,se eu tiver seleccionado a 1 faixa de 3 exemplo....muda de faixa mas o select no listbox fica na 1 o que estou tentando é que o select do listbo acompanhe a passagem das faixas.

Abraço 

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,2k
    • Posts
      652k
×
×
  • Criar Novo...