Odtwarzacz mp3 sprawdzenie

0

Witam, pisze odtwarzacz mp3 w delphi ale mam kilka problemów.

  1. nie mogę przesuwać utworów scrollbarem, a zdaję mi się że wszystko jest ok.
  2. kiedy kończy się ostatni utwór nie przeskakuje na pierwszy tylko gra w kółko ostatni tak samo z przyciskiem "następny"
  3. gdy naciskam przycisk "poprzedni" ,gdy jest na 1 utworze wyskakuje błąd.

byłbym wdzięczny za pomoc, jestem początkujący dlatego dla niektórych może się wydawać, ze to błahostki ale ja utknąłem w martwym punkcie.

 unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    OpenDialog1: TOpenDialog;
    MediaPlayer1: TMediaPlayer;
    BitBtn1: TBitBtn;
    ListBox1: TListBox;
    ScrollBar1: TScrollBar;
    Timer1: TTimer;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    BitBtn2: TBitBtn;
    BitBtn3: TBitBtn;
    BitBtn4: TBitBtn;
    TrackBar1: TTrackBar;
    Timer2: TTimer;
    BitBtn5: TBitBtn;
    BitBtn6: TBitBtn;
    BitBtn7: TBitBtn;
    BitBtn8: TBitBtn;
    BitBtn9: TBitBtn;


    procedure ScrollBar1Scroll(Sender: TObject; ScrollCode: TScrollCode;
      var ScrollPos: Integer);

    procedure ListBox1DblClick(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
    procedure BitBtn3Click(Sender: TObject);
    procedure BitBtn4Click(Sender: TObject);
    procedure TrackBar1Change(Sender: TObject);
    procedure Timer2Timer(Sender: TObject);
    procedure BitBtn5Click(Sender: TObject);
    procedure BitBtn6Click(Sender: TObject);
    procedure BitBtn7Click(Sender: TObject);
    procedure BitBtn8Click(Sender: TObject);
    procedure BitBtn9Click(Sender: TObject);


  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  a:integer;

implementation

{$R *.dfm}

procedure SetWavVolume(Lewy,Prawy:Byte);    //dzwiek
begin
  WaveOutSetVolume(Wave_mapper, Integer((Lewy shl 24) or (Prawy shl 8)));
end;

procedure TForm1.BitBtn2Click(Sender: TObject);
begin
      if (opendialog1.Execute) then
    begin
    listbox1.Items.Add(opendialog1.fileName);  // dodaje do playlisty
    a:=a+1;
    Mediaplayer1.FileName :=opendialog1.FileName;
    MediaPlayer1.Open;
    Scrollbar1.Max:= Mediaplayer1.Length;
    Scrollbar1.Position:=Mediaplayer1.Position;
    Label3.Caption:=floattostr(MediaPlayer1.Length);
    Mediaplayer1.play;
end;

end;

procedure TForm1.BitBtn3Click(Sender: TObject);     //info
begin
    Application.MessageBox('Odtwarzacz MP3 ', 'O Programie', MB_OK + MB_ICONinformation);
end;

procedure TForm1.BitBtn4Click(Sender: TObject);       //usun z playlisty
begin
listbox1.DeleteSelected;
a:=a-1;
end;

procedure TForm1.BitBtn5Click(Sender: TObject);
begin
mediaplayer1.Rewind;
if listbox1.ItemIndex<0   then
begin
  mediaplayer1.Stop;
    scrollbar1.position:=0;
    Label1.Caption:='00:00';
    Label3.Caption:='00:00';
  end;
end;


procedure TForm1.BitBtn6Click(Sender: TObject);
begin
  Mediaplayer1.filename:=Listbox1.items.Strings[listbox1.ItemIndex];
  mediaplayer1.open;
  mediaplayer1.play;
  Label3.Caption:=floattostr(MediaPlayer1.Length);
end;

procedure TForm1.BitBtn7Click(Sender: TObject);
begin
mediaplayer1.pause;
end;

procedure TForm1.BitBtn8Click(Sender: TObject);
begin
    if listbox1.ItemIndex>=a then
    begin
      listbox1.ItemIndex:=0;
      Mediaplayer1.filename:=Listbox1.items.Strings[listbox1.ItemIndex];
      mediaplayer1.open;
      mediaplayer1.play;
      Label3.Caption:=floattostr(MediaPlayer1.Length);
    end;
  listbox1.itemindex:=listbox1.ItemIndex+1;
  Mediaplayer1.filename:=Listbox1.items.Strings[listbox1.ItemIndex];
  mediaplayer1.open;
  mediaplayer1.play;
  Label3.Caption:=floattostr(MediaPlayer1.Length);
end;

procedure TForm1.BitBtn9Click(Sender: TObject);
begin
if listbox1.ItemIndex<0 then
    begin
      listbox1.ItemIndex:=a;
      Mediaplayer1.filename:=Listbox1.items.Strings[listbox1.ItemIndex];
      mediaplayer1.open;
      mediaplayer1.play;
      Label3.Caption:=floattostr(MediaPlayer1.Length);
    end;

   if listbox1.ItemIndex>=0 then
   begin
  listbox1.itemindex:=listbox1.ItemIndex-1;
  Mediaplayer1.filename:=Listbox1.items.Strings[listbox1.ItemIndex];
  mediaplayer1.open;
  mediaplayer1.play;
  Label3.Caption:=floattostr(MediaPlayer1.Length);
   end;

end;

procedure TForm1.ListBox1DblClick(Sender: TObject);
begin
if Listbox1.ItemIndex <> -1 then
begin
  Mediaplayer1.filename:=Listbox1.items.Strings[listbox1.ItemIndex];
  Mediaplayer1.open;
  Mediaplayer1.play;
  Label3.Caption:=floattostr(MediaPlayer1.Length);
end;
end;

procedure TForm1.ScrollBar1Scroll(Sender: TObject; ScrollCode: TScrollCode;
  var ScrollPos: Integer);        // przewijanie cos nie dziala
begin
    scrollbar1.Max:=mediaplayer1.Length;
    Scrollbar1.Position:=Mediaplayer1.Position;
end;


procedure TForm1.Timer1Timer(Sender: TObject);
begin
if mediaplayer1.FileName='' then  exit;
Scrollbar1.position:=Mediaplayer1.position;
Scrollbar1.Max:= Mediaplayer1.Length;
Label1.Caption:=floattostr(MediaPlayer1.Position);
  if scrollbar1.position=scrollbar1.Max then
  begin
  Scrollbar1.Max:= Mediaplayer1.Length;
  listbox1.itemindex:=listbox1.ItemIndex+1;
  Mediaplayer1.filename:=Listbox1.items.Strings[listbox1.ItemIndex];
  mediaplayer1.open;
  Label3.Caption:=floattostr(MediaPlayer1.Length);
  mediaplayer1.play;
    if listbox1.ItemIndex>=a then
    begin
    Scrollbar1.Max:= Mediaplayer1.Length;
    listbox1.ItemIndex:=0;
    Mediaplayer1.filename:=Listbox1.items.Strings[listbox1.ItemIndex];
    mediaplayer1.Open;
    Label3.Caption:=floattostr(MediaPlayer1.Length);
    mediaplayer1.play;
    end;
  end;
end;


procedure TForm1.Timer2Timer(Sender: TObject);
begin
  a:=(Form1.ListBox1.Count)
end;

procedure TForm1.TrackBar1Change(Sender: TObject);
begin
   SetWavVolume(trackbar1.Position,trackbar1.position);
end;



end.

0

przewijanie Ci nie dziala bo zastanow sie co do czego przypisujesz? A do B czy B do A.

zamiast stosowac zmienna "a" uzyj listbox1.Items.Count i nie musisz nic dodawac odejmowac, count zasze zwroci Ci ilosc itemow. najprawdopodobniej gdzies z ta zmienna "a" masz problem.
jak piszesz ze wyskakuje Ci blad to zawsze jeszcze napisz jaki. obstawiam ze index out of bounds, czyli probujesz sie odwolac do itema ktory nie isnieje.

    Scrollbar1.Max:= Mediaplayer1.Length;
    listbox1.ItemIndex:=0;
    Mediaplayer1.filename:=Listbox1.items.Strings[listbox1.ItemIndex];
    mediaplayer1.Open;
    Label3.Caption:=floattostr(MediaPlayer1.Length);
    mediaplayer1.play;

czemu najpierw przypisujesz Scrollbar1.Max:= Mediaplayer1.Length; a dopiero potem ladujesz nowy plik? chyba nie ta kolejnosc.

po drugie napisz sobie wlasna procedure ladujPlik(nazwaPliku:string) w ktorej bedziesz ladowal plik do mediaplayera, przypisywal dlugosc itd.. bo tak to masz milion razy to samo powtorzone w kodzie a tak sie nie robi. jesli w kilku miejscach w programie musisz wykonac identyczne instrukcje, to zrob z nich osobna procedure.

kolejny blad (chociaz bardziej taki nie error tylko warning): uzywasz floattostr do liczb calkowitych. źle. do calkowitych służy IntToStr, FloatToStr jest do zmiennoprzecinkowych.

nie wiem czym to sie rozni ale wszyscy zamiast Listbox1.items.Strings[] pisza po prostu Listbox1.items[].

po co w ScrollBar1Scroll masz scrollbar1.Max:=mediaplayer1.Length;?

a temat raczej do Newbie.

1 użytkowników online, w tym zalogowanych: 0, gości: 1