Media Player in Delphi Trackbar
2. Nov 2013, 21:18
Hallo,
Ich habe einen Media Player in Delphi programmiert. Beim Abspielen bewegt sich die Trackbar zum Fortschritt.Nun wollte ich mal wissen, ob man im Lied springen kann indem man auf eine Stelle in der Trackbar klickt. So wie beim Windows Media player.
Quellcode:
procedure TForm1.Button6Click(Sender: TObject);
begin
if opendialog1.Execute then
begin
listbox1.Items.Add(opendialog1.FileName);
mediaplayer1.FileName:=listbox1.Items[Song];
mediaplayer1.Open;
Timer1.Enabled:=true;
trackbar1.Max:=mediaplayer1.Length;
Label1.Caption:='Jetzt Spielt: '+opendialog1.FileName;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Song:=0;
end;
procedure TForm1.Button7Click(Sender: TObject);
begin
mediaplayer1.Rewind;
Listbox1.Clear;
Song:=0;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
mediaplayer1.Play;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
mediaplayer1.Pause;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
mediaplayer1.Stop;
mediaplayer1.Position:=0;
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
Song:=Song-1;
if Song<0 then Song:=0;
Mediaplayer1.FileName:=Listbox1.Items[Song];
mediaplayer1.Open;
trackbar1.Max:=Mediaplayer1.Length;
Mediaplayer1.Play;
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
Song:=Song+1;
if Song>Listbox1.Count-1 then Song:=0;
Mediaplayer1.FileName:=Listbox1.Items[Song];
mediaplayer1.Open;
trackbar1.Max:=Mediaplayer1.Length;
Mediaplayer1.Play;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
trackbar1.Position:=Mediaplayer1.Position;
if Mediaplayer1.Position=Mediaplayer1.Length then Button5.Click
end;
procedure TForm1.Button8Click(Sender: TObject);
begin
if opendialog2.Execute then
begin
song:=0;
Listbox1.Items.LoadFromFile(opendialog1.FileName);
mediaplayer1.FileName:=listbox1.Items[Song];
mediaplayer1.Open;
Timer1.Enabled:=true;
trackbar1.Max:=Mediaplayer1.Length;
end;
end;
procedure TForm1.Button9Click(Sender: TObject);
begin
if Savedialog1.Execute then
Listbox1.Items.SaveToFile(Savedialog1.FileName);
end;
procedure TForm1.Button10Click(Sender: TObject);
begin
mediaplayer1.Rewind;
end;
MfG
Jansteger
Jan
|