Note that there are some explanatory texts on larger screens.

plurals
  1. POc threads - why does mmsystem (using mciSendString) not play the sound file?
    text
    copied!<p>I want my game to play some sfx. At the beginning, I open some mp3 file <code>mciSendString("open Muzle.mp3 alias Muzle");</code>.</p> <p>My problem is that <code>mciSendString("play Muzle from 0");</code> still causes a little lag and the game has to play the sounds frequently.</p> <p>In another question, I read that using threads will solve the problem. I'm completely new to using threads. The problem now is that the sound doesn't play :p . I verified that the thread runs properly by giving a cout at the end.</p> <p>I have this function now:</p> <pre><code>void Shout(string SoundName){ string FNstr; wstring FNwstr; FNstr = "play " + SoundName + " from 0"; FNwstr.assign(FNstr.begin(), FNstr.end()); mciSendString(FNwstr.c_str(), NULL, 0, NULL); Sleep(2000); cout &lt;&lt; "Test woi\n"; } </code></pre> <p>(I tried without Sleep too. I wonder if I need it, because if the thread reaches the end, it might get deleted and the sound terminated... I'm not sure how threads or the mmsystem work)</p> <p>If I simply call this <code>Shout()</code> function, it will play the sound, do the Sleep(2000), and then cout. Everything worked fine. But I have to use threads, so I try:</p> <pre><code>thread(Shout, "Muzle"); </code></pre> <p>and I got error: abort() has been called. I figured out I may need to detach the thread:</p> <pre><code>thread t(Shout, "Muzle"); t.detach(); </code></pre> <p>With this, everything looked to work fine (after 2 seconds, I see the "Test woi" printed on the console), but no sound was played.</p> <p>Hmm, so thanks for reading everything ^.^ . Do you know how to solve this problem?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload