TMediaPlayerEject (C++)

From RAD Studio Code Examples
Jump to: navigation, search

Description

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.

Code

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 you are done.
    Timer1->Enabled = false;
  }
  else
    TimeOver++;
}

Uses