Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

When has a sound become to the end of playing?

Posted on 1998-04-18
1
201 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 30 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: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

839 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