//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "TMediaPlayerEject.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
// BeginExample: TMediaPlayerEject
// Method: MPlayer.TMediaPlayer.Eject
// Method: MPlayer.TMediaPlayer.Close
// Property: ExtCtrls.TTimer.Enabled

// Warning: CD audio device not installed.

// BeginCode
/*
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++;
}
// EndCode
// EndExample: TMediaPlayerEject
//---------------------------------------------------------------------------

