... play a mp3 after the other, with 2 components?

Author: AlexSystems
Homepage: http://www.alexsystems.hpg.com.br

Category: Multimedia

unit Unit1;

interface

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

type
  
TForm1 = class(TForm)
    StatusBar1: TStatusBar;
    MediaPlayer1: TMediaPlayer;
    MediaPlayer2: TMediaPlayer;
    Timer1: TTimer;
    Label1: TLabel;
    ProgressBar1: TProgressBar;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    OpenDialog1: TOpenDialog;
    Label2: TLabel;
    Timer3: TTimer;
    ProgressBar2: TProgressBar;
    Timer4: TTimer;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    procedure Timer1Timer(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Timer3Timer(Sender: TObject);
    procedure Timer4Timer(Sender: TObject);
  private
    
{ Private declarations }
  
public
    
{ Public declarations }
  
end;

var
  
Form1: TForm1;
  PlayerX: string;
  PlayerXXX: string;

implementation

{$R *.dfm}

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  
ProgressBar1.Position := trunc(mediaplayer1.Position / mediaplayer1.Length * 100);
  if mediaplayer1.Position = mediaplayer1.Length then
    
timer1.Enabled := False;


  if ProgressBar1.Position = 100 then    /// para quando acaba o mp3 iniciar outro mp3
  
begin
    
MediaPlayer1.Close;
    PlayerXXX      := Label1.Caption;
    label2.Caption := PlayerXXX;
    MediaPlayer2.FileName := PlayerXXX;
    Mediaplayer2.TimeFormat := tfMilliSeconds;
    MediaPlayer2.Open;
    MediaPlayer2.play;

    button2.Enabled := False;
    button3.Enabled := False;

    timer3.Interval := 100;
  end;
end;



procedure TForm1.Button1Click(Sender: TObject);
begin
  with 
OpenDialog1 do
    
/// abre o dialogo
    
if Execute then 
    begin
      
PlayerX        := OpenDialog1.FileName;
      Label1.Caption := PlayerX;


      with MediaPlayer1 do 
      begin
        
MediaPlayer1.FileName   := PlayerX;
        Mediaplayer1.TimeFormat := tfMilliSeconds;
        MediaPlayer1.Open;
      end;
    end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  
Mediaplayer1.play;
  timer1.Interval := 100;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  
Mediaplayer1.pause;
end;

procedure TForm1.Timer3Timer(Sender: TObject);
begin
  
ProgressBar2.Position := trunc(mediaplayer2.Position / mediaplayer2.Length * 100);
  if mediaplayer2.Position = mediaplayer2.Length then
    
timer3.Enabled := False;
end;

end.

 

printed from
www.swissdelphicenter.ch
developers knowledge base