Board index » cppbuilder » TMEdiaPlayer: play audio files in repeat mode

TMEdiaPlayer: play audio files in repeat mode


2004-04-29 05:16:02 AM
cppbuilder68
Hi,
There's a way using TMediaPlayer component, to play an audio files in
"repeat" mode? When the file ends to play, TMediaPlayer must repeat it
infinite times, until the program is closed or the utent kill it.
I open an audio file with this code:
//-------------------------
...
//play intro sound
if (FileExists(sound)) {
try {
mpPlayer->FileName = sound;
mpPlayer->Open();
mpPlayer->Play();
} catch (Exception &E) {}
}
//--------------------------
Thenks
Mario Sernicola
 
 

Re:TMEdiaPlayer: play audio files in repeat mode

"Mario Sernicola" < XXXX@XXXXX.COM >wrote in message
Quote
There's a way using TMediaPlayer component, to play
an audio files in "repeat" mode?
TMediaPlayer does not support that. You will have to either:
1) use a separate timer that checks the TMediaPlayer's Mode property
periodically and calls Play() when needed
2) don't use TMediaPlayer at all. If all you are trying to do is play a
sound file, then use the Win32 API PlaySound() function instead. It has a
SND_LOOP flag available that you can use to do what you are asking for.
Gambit
 

Re:TMEdiaPlayer: play audio files in repeat mode

Quote
1) use a separate timer that checks the TMediaPlayer's Mode property
periodically and calls Play() when needed
If I set an Interval property of 500 ms for a TTimer (for example), can this
disturb my application in efficiently terms?
Quote
2) don't use TMediaPlayer at all. If all you are trying to do is play a
sound file, then use the Win32 API PlaySound() function instead. It has a
SND_LOOP flag available that you can use to do what you are asking for.
I need to play mp3 too and more sounds at the same time... (Actually I use 2
separated TMediaPlayer components) and I need to stop them in any instant.
Mario
 

{smallsort}

Re:TMEdiaPlayer: play audio files in repeat mode

Hi Mario,
You can use the TMediaPlayer::OnNotify event to determine when to
replay the sound...
void __fastcall TForm1::MediaPlayer1Notify(TObject *Sender)
{
if (MediaPlayer1->Mode == mpPlaying)
{
// (MediaPlayer1->AutoRewind == true)
MediaPlayer1->Play();
MediaPlayer1->Notify = true;
}
}
HTH,
Mario Sernicola wrote:
Quote
Hi,

There's a way using TMediaPlayer component, to play an audio files in
"repeat" mode? When the file ends to play, TMediaPlayer must repeat it
infinite times, until the program is closed or the utent kill it.
 

Re:TMEdiaPlayer: play audio files in repeat mode

"Damon Chandler (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote
You can use the TMediaPlayer::OnNotify event
to determine when to replay the sound...
The trick is, however, that you need to set the Notify property to true
prior to calling Play(), and then you can't call anything else with Notify
set to true until the Play() finishes, otherwide the OnNotify event can get
messed up.
Quote
MediaPlayer1->Play();
MediaPlayer1->Notify = true;
You need to set Notify before calling Play(), not afterwards:
MediaPlayer1->Notify = true;
MediaPlayer1->Play();
If you set it afterwards, it won't have any effect on Play() at all, and the
OnNotify event won't be triggered.
Gambit