From Clomosy Docs

Revision as of 08:39, 2 August 2024 by ClomosyManager (talk | contribs) (Created page with "TclMediaPlayer is a component used for playing audio files. It allows you to perform basic media control functions such as playing, pausing, and stopping audio files. This component is particularly useful when you want to include audio content in your application. {| class="wikitable" style="border: 2px solid #c3d7e0" ! style="background-color: #c3d7e0"| Feature !!style="background-color: #c3d7e0"| Use of !!style="background-color: #c3d7e0"|Definition |- |TclMediaPlaye...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

TclMediaPlayer is a component used for playing audio files. It allows you to perform basic media control functions such as playing, pausing, and stopping audio files. This component is particularly useful when you want to include audio content in your application.

Feature Use of Definition
TclMediaPlayer MediaPlayer1 : TclMediaPlayer A variable belonging to the TclMediaPlayer class is created.
FileName MediaPlayer1.FileName = clPathCombine('FonMusic1.mp3',Clomosy.AppFilesPath); Specifies the media file name played by the current media player. In the example, it takes the FonMusic1.mp3 file located in the project's directory.
Play MediaPlayer1.Play; It starts playing the media file. If the media file has been paused, the Play feature resumes the file from where it was paused. If the media file was previously stopped, the Play feature starts playing the file from the beginning.
Stop MediaPlayer1.Stop It stops playing the media file and rewinds it to the beginning. This means that the playback of the media file is completely terminated.
CurrentTime MediaPlayer1.CurrentTime = 0; Specifies the current playback position. CurrentTime is measured in 100ns. In the example, the time is set to take the audio file to the beginning.
Duration ShowMessage(MediaPlayer1.Duration) Specifies the total play time of the current media file attached to the media player. Duration is measured in 100ns.
State ShowMessage(MediaPlayer1.State) Specifies whether the current attached Media is playing or is stopped. If the current media file is not assigned or supported, then State is set to Unavailable. If the current media file is playing, then State is set to Playing, otherwise it is set to Stopped. (0:Unavailable, 1:Playing, 2:Stopped)
Volume MediaPlayer1.Volume = 0.3; Specifies the audio volume of the current media file. Volume takes values in the range from 0 through 1. If Volume is 1, then the media file is played at the maximum native volume. If Volume is 0, then the media file is mute. If there is no media file attached to the current media player, then Volume is 1.

Example:
The example creates a user interface for playing and stopping a media file. First, a form is created from the TCLForm class, and a TclMediaPlayer component is added to the form to load an audio file (uefa_League.wav). A panel (Panel1) is then created on the form, and two buttons (Start and Stop) are added to this panel. When the Start button is clicked, the media file is played from the beginning (resetting CurrentTime and calling Play); when the Stop button is clicked, the media file is stopped (calling Stop). The button events (tbeOnClick) are linked to a procedure called trigger, which checks which button was clicked and performs the appropriate media control action.

TRObject Syntax
  var
   MyForm:TCLForm;
   MediaPlayer1 : TclMediaPlayer;
   Panel1 : TclPanel;
   Buton : TclButton;
   i : Integer;
   
  void trigger; 
  var
    clickedBtn:TClButton;
  {
    clickedBtn = TClButton(MyForm.Clsender); 
    if (clickedBtn.Hint == '0')
    {
      MediaPlayer1.CurrentTime = 0;
      MediaPlayer1.Play;
    }else
    {
       MediaPlayer1.Stop;
       MediaPlayer1.Volume = 0.3;
    }
  }
  
  {
    MyForm = TCLForm.Create(Self);
    
    MyForm.AddAssetFromUrl('https://clomosy.com/demos/uefa_League.wav');
    MediaPlayer1 = TclMediaPlayer.Create(MyForm);
    MediaPlayer1.FileName = clPathCombine('uefa_League.wav',Clomosy.AppFilesPath);
    
    Panel1 = MyForm.AddNewPanel(MyForm,'Panel1');
    Panel1.Align = alCenter;
    Panel1.Width = MyForm.clWidth / 2;
    Panel1.Height = MyForm.clHeight / 6;
    
    for (i = 0 to 1)
    {
      if(i == 0)
      {
        Buton = MyForm.AddNewButton(Panel1,'Buton'+IntToStr(i), 'Start');
        Buton.Align = AlLeft;
      }else
      {
        Buton = MyForm.AddNewButton(Panel1,'Buton'+IntToStr(i), 'Stop'); 
        Buton.Align = AlRight;
      }
      Buton.width = Panel1.width / 2;
      Buton.Hint = IntToStr(i);
      MyForm.AddNewEvent(Buton,tbeOnClick,'trigger');
    }
    MyForm.Run;
  }
Base Syntax
var
 MyForm:TCLForm;
 MediaPlayer1 : TclMediaPlayer;
 Panel1 : TclPanel;
 Buton : TclButton;
 i : Integer;
 
procedure trigger; 
var
  clickedBtn:TClButton;
begin
  clickedBtn := TClButton(MyForm.Clsender); 
  if clickedBtn.Hint = '0' then 
  begin
    MediaPlayer1.CurrentTime := 0;
    MediaPlayer1.Play;
  end else
  begin
    MediaPlayer1.Stop;
    MediaPlayer1.Volume := 0.3;
  end;
end;

begin
  MyForm := TCLForm.Create(Self);
  
  MyForm.AddAssetFromUrl('https://clomosy.com/demos/uefa_League.wav');
  MediaPlayer1 := TclMediaPlayer.Create(MyForm);
  MediaPlayer1.FileName := clPathCombine('uefa_League.wav',Clomosy.AppFilesPath);
  
  Panel1 := MyForm.AddNewPanel(MyForm,'Panel1');
  Panel1.Align := alCenter;
  Panel1.Width := MyForm.clWidth / 2;
  Panel1.Height := MyForm.clHeight / 6;
  
  for i := 0 to 1 do
  begin
    if i = 0 then
    begin
      Buton := MyForm.AddNewButton(Panel1,'Buton'+IntToStr(i), 'Start');
      Buton.Align := AlLeft;
    end else
    begin
      Buton := MyForm.AddNewButton(Panel1,'Buton'+IntToStr(i), 'Stop'); 
      Buton.Align := AlRight;
    end;
    Buton.width := Panel1.width / 2;
    Buton.Hint := IntToStr(i);
    MyForm.AddNewEvent(Buton,tbeOnClick,'trigger');
  end;
  MyForm.Run;
end;