0

I'm creating a C# application, in which I need to reproduce a MP3 file. As soon as the file has been completely reproduced (not before) I want execute other methods.

The problem is that, since surely a thread is used for reproduce sounds, all the subsequent actions are executed immediately, without waiting for the complete reproduction of the mp3 file.

The code is:

 gioco.playSound(true);

 if (gioco.feedbackNao && naoConnect)
 {
    nao.talkNao("Bravo! Continua così.");
 }
 else if (gioco.feedbackVocale && speech.isFound)
 {
    speech.pronunciaFraseCorretta();
 }

#Class UtilityGame
public void playSound(bool rispostaCorretta)
{
   playerOK = new WMPLib.WindowsMediaPlayer();
   playerOK.URL = Directory.GetCurrentDirectory() + "/Resources/Sound/ok.mp3";
   playerOK.controls.play();
} 

So, when I try to execute playSound method, at the first line, the next instructions are processed before the sounds ends.

Alberto Solano
  • 7,972
  • 3
  • 38
  • 61
bircastri
  • 153
  • 4
  • 13
  • If I understand your issue correctly, you want to execute the code -after- the mp3 finished playing. So just would have to bind your "after"-code to an event which will be fired after the mp3 is finished playing (maybe like gioco.SoundFinished or something - have a look into the api). – Michael Mar 21 '14 at 08:15
  • because Play run on another thread you should join that thread – giammin Mar 21 '14 at 08:38

0 Answers0