?
Solved

Playing a sound loop

Posted on 2005-03-31
10
Medium Priority
?
243 Views
Last Modified: 2010-04-05
Hi All,
I have a sound loop (the end matches the begining) that I would like to play as my application is used. I can either use wav or mp3 (prefer mp3). Also, it must be able to support several sounds being played at the same time as the loop. Please help!
0
Comment
Question by:maxb
  • 6
  • 3
10 Comments
 

Author Comment

by:maxb
ID: 13673965
Oh, I also would like to avoid any directX overhead etc. And since this is a commercial app, please do not suggest using shareware DLLs.
0
 
LVL 13

Accepted Solution

by:
BlackTigerX earned 1200 total points
ID: 13674485
something like (add MMSystem to the uses):

PlaySound(pChar('c:\somefile.wav'),0, SND_SYNC or SND_LOOP or SND_NOSTOP);
0
 

Author Comment

by:maxb
ID: 13674504
can I stop that loop and reassing another wav to play? the music changes every 5mins.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 13

Expert Comment

by:BlackTigerX
ID: 13674505
missed an A

PlaySound(pChar('C:\WINNT\Help\iisHelp\iis\htm\tutorial\eagle2.wav'),0, SND_ASYNC or SND_LOOP or SND_NOSTOP);
0
 
LVL 13

Expert Comment

by:BlackTigerX
ID: 13674516
yes, just put another line

PlaySound(pChar('C:\WINNT\media\ir_begin.wav'),0, SND_ASYNC or SND_LOOP);

notice there's no SND_NOSTOP... that will stop the other sound and continue with this one
0
 
LVL 13

Expert Comment

by:BlackTigerX
ID: 13674532
or if you have that in some Timer, you just need to change the filename

PlaySound(pChar(FileNameThatIsDifferentEveryFiveMinutes),0, SND_ASYNC or SND_LOOP);
0
 

Author Comment

by:maxb
ID: 13674641
Ok with MMSystem it looks like it stops ALL sounds playing and starts playing yours. I need to be able to play the music but still have the sound effects. Am i interpreting it incorrectly?
0
 
LVL 13

Expert Comment

by:BlackTigerX
ID: 13675968
gets tricky... let me play some more with this function and maybe something else
0
 
LVL 13

Expert Comment

by:BlackTigerX
ID: 13676037
how about using a MediaPlayer and the PlaySound function... here's some code:

play the background musc on the MediaPlayer and whatever sounds (effects?) using the PlaySound, use the MediaPlayer1Notify event to loop, set the MediaPlayer AutoRewind to True

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    MediaPlayer1: TMediaPlayer;
    Button1: TButton;
    Button2: TButton;
    procedure MediaPlayer1Notify(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.MediaPlayer1Notify(Sender: TObject);
begin
  if (MediaPlayer1.NotifyValue = nvSuccessful) then
    MediaPlayer1.Play
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  MediaPlayer1.Open;
  MediaPlayer1.Play
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  PlaySound(pChar('C:\WINNT\media\ir_begin.wav'),0, SND_ASYNC or SND_NOSTOP);
end;

end.
0
 
LVL 35

Expert Comment

by:Slick812
ID: 13678278
use the media player with a Notification event and then restart the mp3 in the notification event for the finish of playing the mp3, , , ,then to stop the looping mp3 just call stop for the mediaPlayer

with MediaPlayer1 do
  begin
  Filename :='C:\mp38.mp3';
  Open;
  Notify := True;
  Play;
  end;


procedure Tform1.MediaPlayer1Notify(Sender: TObject);
begin  /// loops the song
MediaPlayer1.Play;
MediaPlayer1.Notify := True;
end;
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

580 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