Witam, pisze odtwarzacz mp3 w delphi ale mam kilka problemów.
- nie mogę przesuwać utworów scrollbarem, a zdaję mi się że wszystko jest ok.
- kiedy kończy się ostatni utwór nie przeskakuje na pierwszy tylko gra w kółko ostatni tak samo z przyciskiem "następny"
- 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.