?
Solved

Playing a sound loop

Posted on 2005-03-31
10
Medium Priority
?
217 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
[X]
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
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 34

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

765 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