RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TMediaPlayer.AutoEnable Property

Determines whether the media player automatically enables and disables individual buttons in the component.

Pascal
property AutoEnable: Boolean;
C++
__property Boolean AutoEnable;

Use AutoEnable to automatically enable or disable the control buttons on the media player. If AutoEnable is true, the media player automatically enables or disables its control buttons. The media player determines which buttons to enable or disable by the current mode specified in the Mode property, and the current multimedia device type specified in the DeviceType property. 

AutoEnable overrides the EnabledButtons property. The buttons enabled or disabled automatically by the media player supersede any buttons enabled or disabled with EnabledButtons

If AutoEnable is false, the media player does not enable or disable buttons. The buttons must enabled or disabled with the EnabledButtons property. 

The following table shows whether buttons are automatically enabled or disabled for each device mode:

Button 
Play 
Record 
Stop 
Not Open 
Back  
Disabled  
Eject  
Disabled  
Next  
Disabled  
Pause  
Disabled  
Disabled  
Play  
Disabled  
Disabled  
Disabled  
Prev  
Disabled  
Record  
Disabled  
Disabled  
Disabled  
Step  
Disabled  
Stop  
Disabled  
Disabled  
Disabled  

 

C++ Examples: 

//
//This example demonstrates the use of TMediaPlayer component. Assuming 2 buttons
//for Open and Stop are present on the form.
//Note: AutoEnable must be set to false to be able to control
//the buttons manually.
//
void __fastcall TForm2::btOpenClick(TObject *Sender)
{
    TOpenDialog* OpenMediaDialog;

    OpenMediaDialog = new TOpenDialog(this);
    OpenMediaDialog->Filter = "All Video Files (*.avi)|*.avi";
  // There are avi files in
  // C:\Documents and Settings\All Users\Documents\RAD Studio\6.0\Demos\DelphiWin32\VCLWin32\CoolStuff
    if (OpenMediaDialog->Execute())
    {
        /* Assign a file to the media player */
        MediaPlayer1->FileName = OpenMediaDialog->FileName;

        /* Check if the file exists and is not a directory */
        if ((FileExists(OpenMediaDialog->FileName)) &&
           (!DirectoryExists(OpenMediaDialog->FileName)))
        {
            /* Open the files */
            MediaPlayer1->Wait = true;
            MediaPlayer1->Open();
            MediaPlayer1->Play();

            /* Override automatic button controlling */
            MediaPlayer1->EnabledButtons =
                TButtonSet() <<
                TMPBtnType::btPause <<
                TMPBtnType::btStop <<
                TMPBtnType::btPlay;


            /* Enable  the stop button */
            btStop->Enabled = true;
            btOpen->Enabled = false;
        }
    }

    delete OpenMediaDialog;
}

void __fastcall TForm2::btStopClick(TObject *Sender)
{
    /* Stop and close the media */
    MediaPlayer1->Stop();
    MediaPlayer1->Close();

    MediaPlayer1->EnabledButtons = TButtonSet();

    /* Enable open button again */
    btOpen->Enabled = true;
}

void __fastcall TForm2::FormCreate(TObject *Sender)
{
    /* Disable all buttons */
    MediaPlayer1->AutoEnable = false;
    MediaPlayer1->EnabledButtons = TButtonSet();
}

void __fastcall TForm2::MediaPlayer1PostClick(TObject *Sender,
          TMPBtnType Button)
{
    if (Button == TMPBtnType::btStop)
        btStop->Click();
}

 

Delphi Examples: 

{
This example demonstrates the use of TMediaPlayer component. Assuming 2 buttons
for Open and Stop are present on the form.
Note: AutoEnable must be set to false to be able to control
the buttons manually.
}

procedure TForm2.btOpenClick(Sender: TObject);
var
  OpenMediaDialog : TOpenDialog;
begin
  OpenMediaDialog := TOpenDialog.Create(Self);
  OpenMediaDialog.Filter := 'All Video Files (*.avi)|*.avi';
  // There are avi files in
  // C:\Documents and Settings\All Users\Documents\RAD Studio\6.0\Demos\DelphiWin32\VCLWin32\CoolStuff
  if OpenMediaDialog.Execute() then
  begin
    { Assign a file to the media player }
    MediaPlayer1.FileName := OpenMediaDialog.FileName;

    { Check if the file exists and is not a directory }
    if (FileExists(OpenMediaDialog.FileName)) and
       (not DirectoryExists(OpenMediaDialog.FileName)) then
    begin
      { Open the files }
      MediaPlayer1.Wait := true;
      MediaPlayer1.Open;
      MediaPlayer1.Play;

      { Override automatic button controlling }
      MediaPlayer1.EnabledButtons :=
        [TMPBtnType.btPause, TMPBtnType.btStop, TMPBtnType.btPlay];

      { Enable  the stop button }
      btStop.Enabled := true;
      btOpen.Enabled := false;
    end;
  end;

  OpenMediaDialog.Free;
end;

procedure TForm2.btStopClick(Sender: TObject);
begin
  { Stop and close the media }
  MediaPlayer1.Stop;
  MediaPlayer1.Close;

  MediaPlayer1.EnabledButtons := [];

  { Enable open button again }
  btOpen.Enabled := true;
end;

procedure TForm2.FormCreate(Sender: TObject);
begin
  { Disable all buttons }
  MediaPlayer1.AutoEnable := false;
  MediaPlayer1.EnabledButtons := [];
end;

procedure TForm2.MediaPlayer1PostClick(Sender: TObject;
  Button: TMPBtnType);
begin
  if Button = TMPBtnType.btStop then
     btStop.Click;
end;

 

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!