• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 331
  • Last Modified:

Using TMediaPlayer to Play Wave File Sequentially..., Second after first wave file finished.

   I've problems using TMediaplayer to play Wave file
    1. I have wave files like this... Wav1.Wav, Wav2.Wav, ... and so on.
    2. I want to play continueous wave phrase recorded in each wave files but problems arise
       When I use TMediaplayer, I named it "Media1" and put the code like this
       with Media1 do begin
          Close;
          FileName := 'C:\Wav1.Wav';
          Open;
          Play;

          FileName := 'C:\Wav2.Wav';
          Open;
          Play;
         
          ... and so on
       End;
   Problems is that Media1 doesn't seem to play Wav1.wav, it only play the last file in the code.
What I know for sure is that the code excuted simultaneously after it play the first file, it execute the next command immediately. That is, it stop playing the first file and immediately play the second file. That make the code unacceptable. I've tried using
   Media1.Wait := True;
   Media1.Play;
   It doesn't seem to work. Result is the same as before.
   So tell me how to make it play the first file till it finished. Then play the second file so that it result in sequentially voice...
0
DOOM_DAEMON
Asked:
DOOM_DAEMON
  • 2
1 Solution
 
geobulCommented:
Hi,

Try

...
Wait := true;
Play;
...

This is not recommended if the palyed media is long.

Regards, Geo
0
 
tongaliteCommented:
Hi,
Try this.

Good luck
T.
=======================

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, MPlayer;

type
  TForm1 = class(TForm)
    MediaPlayer1: TMediaPlayer;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);


  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  filename:string;
implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin

  with MediaPlayer1 do
  begin
    FileName := 'C:\windows\media\ding.wav';
    AutoRewind := True;

      Open;          { Open Media Player }
      Wait := True;  { Waits until sounds is done playing to return }
      Play;          { Play sound }
      Play;          { Play again after first playing is completed }


    FileName := 'C:\windows\media\chord.wav';
    AutoRewind := True;

      Open;          { Open Media Player }
      Wait := True;  { Waits until sounds is done playing to return }
      Play;          { Play sound }
      Play;          { Play again after first playing is completed }

   FileName := 'C:\windows\media\chimes.wav';
   AutoRewind := True;

      Open;          { Open Media Player }
      Wait := True;  { Waits until sounds is done playing to return }
      Play;          { Play sound }
     Close;
     end;
         end;
             end.
0
 
DOOM_DAEMONAuthor Commented:
   I now Know where problems are. Because of placing Wait := True before Open; like this
    FileName := 'C:\Windows\Media\Chimes.wav';
    Wait := true;
    Open;
    Play;

    That cause the program to run like wait:= false; After doing code like you, it works! Thanks. And thanks to all of you helping me here.
0
 
geobulCommented:
Hi DOOM_DAEMON,

What's wrong with my comment? The key was setting Wait to true before Open. I think I pointed that out first. The accepted answer will play each file twice. Is that what you are looking for?

Regards, Geo
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now