-2

So I am doing a game in assembly language and I am using the PlaySound() function to play a background song. I want to do that after I "die" in the game, another sound file will start playing a sound file, and at the same time will stop the other background song.

MicroVirus
  • 5,324
  • 2
  • 28
  • 53
jeff style
  • 61
  • 1
  • 7
  • 1
    You have not provided nearly enough detail. What "PlaySound()" function? Which version of Windows (or DOS, I suppose)? What have you written so far? In what way is it failing to behave in the way that you expect? – David Hoelzer Jun 06 '15 at 00:15
  • i am using win 8 i have written a lot of code because its a game. And i run the sound file like that "invoke PlaySound,offset "the name of the file",NULL,SND_ASYNS" – jeff style Jun 06 '15 at 00:19
  • 2
    If you are unwilling to share code and explain how it is failing to do what you expect it to, you may find that no one here will assist you. :) – David Hoelzer Jun 06 '15 at 00:21
  • i dont think i can send 1500 rows of code... – jeff style Jun 06 '15 at 00:21
  • but i did send how do i provide a sound in the game – jeff style Jun 06 '15 at 00:22
  • 1
    I'm not asking you to. Rephrase your problem into a specific question that revolves around a small portion of your code that is not behaving in the way that you expect or that you are unsure of how to modify. – David Hoelzer Jun 06 '15 at 00:22
  • I have a game, in the main area i have a sound file that acts like the background song and all the window properties (all the window messages and etc). But out of the main area(before the main) I have a sound that i want to play, that will overcome the background sound file, and will play it and not the background sound. I know that in the playsound function there is the flags that do things like that(the "fdwSound") but I don't know which flag should I enter to do such a thing. I hope its more clear now – jeff style Jun 06 '15 at 00:29
  • PlaySound should automatically stop the last sound played by PlaySound. If it's not doing this then there's no flag that will make it do it. – Ross Ridge Jun 06 '15 at 03:43
  • Develop your understanding of an api with a high level language. Then write the asm code. Don't ask for help with code that you refuse to show. Please provide mcve. – David Heffernan Jun 06 '15 at 05:57

1 Answers1

1

Read the documentation.

PlaySound function

pszSound
A string that specifies the sound to play. The maximum length, including the null terminator, is 256 characters. If this parameter is NULL, any currently playing waveform sound is stopped. To stop a non-waveform sound, specify SND_PURGE in the fdwSound parameter.

...

fdwSound
Flags for playing the sound. The following values are defined.
...
SND_ASYNC
The sound is played asynchronously and PlaySound returns immediately after beginning the sound. To terminate an asynchronously played waveform sound, call PlaySound with pszSound set to NULL.

So you need to call PlaySound() three times - one to start the background music, one to stop it, and one to play the next sound.

invoke PlaySound,offset "the name of the bkgnd file",NULL,SND_ASYNC
...
invoke PlaySound,NULL,NULL,SND_ASYNC
invoke PlaySound,offset "the name of the other file",NULL,SND_ASYNC
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770