PlaySound() function

closed account (zwA4jE8b)
I am temporarily using the PlaySound Function to play audio during my game. Without using a 3rd party library does windows support pausing and stopping the audio?
PlaySound() allows stopping, yes. I think it is not the case for pause, though. Check MSDN Online.
I suggest you to use a 3rd party library. PlaySound only can play WAVs, and is not able to play more files in the same time.
I personally use the Bass Library.
All you have to do is:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include "bass.h"
int main()
{
  if(!BASS_Init(-1,44100,0,0,0)) //Initializes BASS Library. Needed only once.
     return 0;
  HSTREAM AudioChannel = BASS_StreamCreateFile(false,"Audio File Name Here plox",0,0,0);
  //Create a Audio Stream from a File.
  BASS_ChannelPlay(AudioChannel,true);
  //Plays the Stream.
  while(BASS_ChannelIsActive(AudioChannel))
  {
    //Waits until song/audio file ends.
    Pause(500);
  }
  BASS_Free();
  return 1;
}

This is the complete code you need to play an audio file.
BASS Library natively supports WAVs, MP3s, OGGs and has many plugins like WMA, MP4...
Link: www.un4seen.com/

Other functions are:
BASS_ChannelStop(HANDLE) - Stops a Stream
BASS_ChannelPause(HANDLE) - Pauses a Stream
HANDLE is AudioChannel over. (I mean, you can do BASS_ChannelStop(AudioChannel) and BASS_ChannelPause(AudioChannel). Remember, ChannelStop stops a channel, ChannelPause pauses it and you can re-play it with BASS_ChannelPlay. )
Last edited on
closed account (zwA4jE8b)
Does Bass play Asynchronously?
There's also MCI if you don't want a 3rd party library.

http://msdn.microsoft.com/en-us/library/dd757151%28v=VS.85%29.aspx
I think it does, creative. Afaik it automatically creates its own thread to manage audio, as far as you don't specify a flag i don't actually remember.
> I suggest you to use a 3rd party library

Totally useless.
Never use external libraies in Windows, where everything is native

There are dozens of methods to manage sounds (MM apis, Dx, etc)
Ha? Do something like bass or irrlicht can do with the same amount of written lines.
And remember, DX is not a native windows method.
Last edited on
Topic archived. No new replies allowed.