[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

When has a sound become to the end of playing?

Posted on 1998-04-18
1
Medium Priority
?
209 Views
Last Modified: 2010-04-06
Hello everyone,

I want to use about 10 different sounds in my application. But when a sound has to start playing, I want to check the position of the playing sound at that moment. The next sound must wait playing until the still playing sound is at the end. How can I do this job?

Thanx for helping,

A Beginning Delphi-developper,
Stefan van Roosmalen.
0
Comment
Question by:roosiedb
1 Comment
 
LVL 5

Accepted Solution

by:
inter earned 120 total points
ID: 1334998
Hi
Use TMediaPlayer component to play the sounds. For example lets say we have 3 sound files as 1.wav, 2.wav and 3.wav which we will going to play in a sequence.

1 - Start a new project with an empty form.
2 - Place a button control on form(is automatically named as button1)
3 - Place a Mediaplayer component on form
4 - add the following decleration to the forms object in the IDE:
   public //this line is there already
       procedure Notification(Sender: TObject); //add this line
   end; // this line is there already
5 - Add the procedure just after the {$R *.dfm}

var
  SeqNo : Integer; //this is sequence no to play the sound files in order
const
   MaxSeq = 3; // this is max number of sounds you want to play
   SoundFiles : array[0..MaxSeq-1] of String =
('1.wav','2.wav','3.wav'); // add the file you want to play here

procedure TForm1.Notification(Sender: TObject); //add this line
begin
  if MediaPlayer1.Mode = mpStopped then
  begin
     SeqNo := (SeqNo + 1) mod MaxSeq; //all the sounds play cyclicly
     MediaPlayer1.Close;
     MediaPlayer1.FileName := SoundFiles[SeqNo];
     MediaPlayer1.Open;
     MediaPlayer1.Play;
  end;
end;

6 - DoubleClick on the form(empy area) to opef FormCreate proc and fill as follows;

procedure TFOrm1.FormCreate(Sender:TObject);
begin
  MediaPlayer1.Wait := false; // media player should not hang our application
  SeqNo := 0;
  MediaPlayer1.FileName := SoundFiles[SeqNo];
  MediaPlayer1.OnNotify := Notification;
  MediaPlayer1.Open;
end;

7 - Doubleclick on Button1 to write

Procedure TForm1.button1click(Sender:TObject);
begin
  If MediaPlayer1.Mode = mpPlaying then
    MediaPlayer1.Pause
  else
    MediaPlayer1.Play;
end;

run the application and be sure that the directory of exe contains the 1.wav, 2.wav, and 3.wav sound files. You can extend the list as you wish. You can hide media player control by setting its visible property to FALSE.

If you want to play sounds in case of an event and do not want to overlap the two sounds, before starting to play something just check

  if MediaPlayer1.Mode = mpStopped then
  begin
     //load and play new tune because previous one is stopped(in general at the end of file)
  end;

Regards,
Igor
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

868 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question