RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TMediaPlayer.Eject Method

Releases the loaded medium from the open multimedia device.

Pascal
procedure Eject;
C++
__fastcall Eject();

Eject is called when the Eject button on the media player control is clicked at runtime. It ejects the loaded medium from the open multimedia device. 

Upon completion, Eject stores a numerical error code in the Error property, and the corresponding error message in the ErrorMessage property. 

The Wait property determines whether control is returned to the application before the Eject method has been completed. The Notify property determines whether Eject generates an OnNotify event.  

C++ Examples: 

 

/*
This code ejects the CD from the CD-ROM player and shuts 
down the media player after 10 seconds. For the code to run
correctly, you must have your CD audio device installed
correctly, and the device must have software-ejecting 
capabilities.
*/

Word TimeOver;

void __fastcall TForm1::FormClick(TObject *Sender)
{
  MediaPlayer1->DeviceType = dtCDAudio;
  MediaPlayer1->Open();
  MediaPlayer1->Play();
  Timer1->Enabled = true;
  TimeOver = 0;
}

void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
  if (TimeOver == 10)
  {
    MediaPlayer1->Eject();
    MediaPlayer1->Close();
    // disable the timer, as we are done
    Timer1->Enabled = false;
  }
  else
    TimeOver++;
}

 

Delphi Examples: 

{
This code ejects the CD from the CD-ROM player and shuts 
down the media player after 10 seconds. For the code to run
correctly, you must have your CD audio device installed
correctly, and the device must have software-ejecting 
capabilities.
} 
var
  TimerOver: Word;

procedure TForm1.FormClick(Sender: TObject);
begin
  MediaPlayer1.DeviceType := dtCDAudio;
  MediaPlayer1.Open;
  MediaPlayer1.Play;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  if TimeOver = 10 then
  begin
    MediaPlayer1.Eject;
    MediaPlayer1.Close;
    { disable the timer, as we are done }
    Timer1.Enabled := False;
  end
  else
    if (MediaPlayer1.Mode = mpOpen) then
     Inc(TimeOver);
end;

 

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!