Playing multiple sounds sequentially

 
Hi,

I want my indicator to play a series of sounds, not just one. For that, I initially tested calling 3 PlaySound() one after the other hoping that the second would only start playing after the first was finished and the same for the third.

Unfortunately I was wrong: in such conditions, even though both of my first two calls to PlaySound return "true", only the third call is effective and the sound is played. It would seem a call to this function immediately stops any previous call.

So how can I do what I want? How can I make the second PlaySound (or other function) only start after the end of the first one? Or, in general, how can I play a sequence of sounds from within a MQL5 Indicator?
 
Martin Bittencourt:
Hi,

I want my indicator to play a series of sounds, not just one. For that, I initially tested calling 3 PlaySound() one after the other hoping that the second would only start playing after the first was finished and the same for the third.

Unfortunately I was wrong: in such conditions, even though both of my first two calls to PlaySound return "true", only the third call is effective and the sound is played. It would seem a call to this function immediately stops any previous call.

So how can I do what I want? How can I make the second PlaySound (or other function) only start after the end of the first one? Or, in general, how can I play a sequence of sounds from within a MQL5 Indicator?

Hello

You can use 3 sets of different indicators or use one particular indicator 3 times. but since theyll play all the same time youll hear only one sound.

Here also there is another option. IDK why youd like to hear a sequential sound set but you also can make a costume sound, attaching all 3 files together and choose the indicator to play that sound file.

 
Uhum:

Hello

You can use 3 sets of different indicators or use one particular indicator 3 times. but since theyll play all the same time youll hear only one sound.

Here also there is another option. IDK why youd like to hear a sequential sound set but you also can make a costume sound, attaching all 3 files together and choose the indicator to play that sound file.

Hmm all these options are unnacceptable for my purposes. How can I ask Metaquotes to change their PlaySound system to put the option of blocking the code until the sound is finished playing?

 
Martin Bittencourt:

Hmm all these options are unnacceptable for my purposes. How can I ask Metaquotes to change their PlaySound system to put the option of blocking the code until the sound is finished playing?

Here's another way (this example will play 3 different sounds at the start of every new bar):

int playSound = 0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   EventSetTimer(1);
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   ArraySetAsSeries(time,true);
   static datetime lastBarTime = 0;
   if (time[0]!=lastBarTime)
   {
      playSound = 3;
      lastBarTime = time[0];
   }
   return(rates_total);
  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
   switch(playSound)
   {
      case (3): PlaySound("Alert"); break;
      case (2): PlaySound("Connect"); break;
      case (1): PlaySound("Email"); break;
   }
   playSound--;
  }

Edit: Oops... you need to add the highlighted line for this example to work repeatedly... 

 
Seng Joo Thio #:

Here's another way (this example will play 3 different sounds at the start of every new bar):

Edit: Oops... you need to add the highlighted line for this example to work repeatedly... 

thank you so much for the code this is exactly what i needed 

although i made it run un demand and play sequence i needed

void OnTimer(){
  if(playSound>0){
     switch(playSound)
      {
         case (5): PlaySound(sound1); break;
         case (4): PlaySound(sound2); break;
         case (3): PlaySound(sound3); break;
         case (2): PlaySound(sound4); break;
         case (1): PlaySound(sound5); break;
      }
      playSound--;
   }
}

void PromptSignal(bool strong,string buyOrSell,int percent){
sound1 = "";
sound2 = "";
sound3 = "";
sound4 = "";
sound5 = "";
if(_Symbol == "XAUUSD"){
   sound1 = "vzone\\gold.wav";
}
if(_Symbol == "US500"){
   sound1 = "vzone\\us500.wav";
}
if(buyOrSell == "buy"){
   if(strong)
      sound2 = "vzone\\strongbuy.wav";
.....

playSound = 5;

this is part of my code and works great