I’m trying to create a video playlist on Delphi, to play
videos by the mediaplayer and does not run all videos chosen,
only the first who rotates...
This happens because before setting the file in Mediaplayer, the index is changed to 0, it is necessary to remove the line ListBox1.ItemIndex
.
procedure TForm1.Button4Click(Sender: TObject);
var
i, Cont: integer;
begin
Cont := 0;
if OpenDialog3.Execute then
begin
for i := 0 to OpenDialog3.Files.count -1 do
ListBox1.Items.Add(OpenDialog3.Files[i]);
//ListBox1.ItemIndex := 0;
MediaPlayer1.FileName := ListBox1.Items[listbox1.ItemIndex];
MediaPlayer1.Open;
MediaPlayer1.Play;
end;
end;
Updating
Create a global variable called VideoAtual
:
var
Form1: TForm1;
VideoAtual: Integer = 0;
Popule the Listbox
with the method below:
procedure CriarPlayList;
var
I: integer;
begin
if OpenDialog1.Execute = False then exit;
for I := 0 to OpenDialog1.Files.count -1 do
ListBox1.Items.Add(OpenDialog1.Files[I]);
ListBox1.ItemIndex := 0;
MediaPlayer1.FileName := ListBox1.Items[ListBox1.ItemIndex];
MediaPlayer1.Open;
MediaPlayer1.Play;
end;
To run the video, use the method below:
procedure ExecutarVideo(Indice: integer);
begin
if Indice >= ListBox1.Items.Count then begin
VideoAtual := 0;
Indice := 0;
end;
ListBox1.ItemIndex := Indice;
MediaPlayer1.Close;
MediaPlayer1.FileName := ListBox1.Items[ListBox1.ItemIndex];
MediaPlayer1.Open;
MediaPlayer1.Play;
end;
At the event Onclick
of MediaPlayer
, add code:
case Button of
btNext: begin
VideoAtual := VideoAtual + 1;
ExecutarVideo(VideoAtual);
end;
btPrev: begin
VideoAtual := VideoAtual - 1;
ExecutarVideo(VideoAtual);
end;
end;
Still not running the added videos, runs only 1 and to.
– Renato Souza
@Renatosouza You select before the video on
ListBox
?– stderr
the code is not to select, it must take the items of listbox1 and put in the player line, even if I run Opendialog and then selecting will not.
– Renato Souza
@Renatosouza I updated the answer.
– stderr
Friend, I appreciate your immense help. But as a beginner, I’m breaking my head to know where I put this code, where I populate. You can help me if you don’t want to. @qmechanik
– Renato Souza
@Renatosouza Dispo. See that example. I created it in Delphi XE3, if you’re using a very old version, you might not be able to compile it, but just look at the code.
– stderr
@Renatosouza If it works, mark the answer as accepted by clicking on the below of the votes. =)
– stderr
@qmwchanik It rotates all the videos I select when I click on search videos? It did not rotate here, only rotates 1 and ready, does not skip to the next ones.
– Renato Souza
The following is a download of my project. https://mega.co.nz/#! fFh3Rb5R! 4QAicX8m7lxV2Ad5V9y8vGs6gfNAmbSv5Ra5pVztyA
– Renato Souza
@Renatosouza I modified that example of mine, see here, just click on "Create Playlist" only. I tested with songs.
– stderr
thanks friend, it worked out, now I will implement to run the images together and ready. Thanks
– Renato Souza
you know how I can make this player take the list of videos from a text file, in txt I have the paths one at the bottom of the other and then I want to play them straight, without having to open the opendialog.
– Renato Souza
@Renatosouza Well, I think you can put the path of images in a array and in the Timer you put the images in a component
TImage
. If you can’t do it, create a question that I try to help better.– stderr
as I do to be able to run the videos without using opendialog, I will add the videos by an external txt.
– Renato Souza
@Renatosouza Just read line by line from txt, first you’ll have to open it using
AssignFile
, from there on a loop you read line-by-line using theReadln
. If I can’t do this, create a new question then I try to respond better.– stderr