SGL
Public Member Functions | Static Public Member Functions | List of all members
GSound Class Reference


This class encapsulates a sound file. More...

#include "gsound.h"

Public Member Functions

 GSound(string filename)
 Creates a Sound object by reading in the contents of the specified file or URL. More...
 
~GSound()
 Frees the memory associated with the sound. More...
 
void play()
 Starts playing the sound. More...
 

Static Public Member Functions

static long getDuration()
 Returns the duration of the sound clip that is currently playing. More...
 
static int getVolume()
 Returns the overall audio volume from 0 (silence) to 100 (full volume). More...
 
static void pause()
 Pauses playing the sound, if it is playing. More...
 
static void playSound(string filename)
 Starts playing the sound if not playing, or unpauses if paused. More...
 
static void setVolume(int volume)
 Sets the overall audio volume from 0 (silence) to 100 (full volume). More...
 
static void stop()
 Stops playing the sound, if it is playing. More...
 

Detailed Description


This class encapsulates a sound file.

The sound file is specified in the constructor and must be a file in either the current directory or a subdirectory named sounds.

The following code, for example, plays the sound file ringtone.wav:

     GSound ringtone("ringtone.wav");
     ringtone.play();
*

You can also use the static playSound method:

     GSound::playSound("ringtone.wav");
*

Constructor & Destructor Documentation

◆ GSound()

GSound ( string   filename)

Creates a Sound object by reading in the contents of the specified file or URL.

◆ ~GSound()

~GSound ( )
virtual

Frees the memory associated with the sound.

Member Function Documentation

◆ getDuration()

long getDuration ( )
static

Returns the duration of the sound clip that is currently playing.

If no clip is playing, returns 0.

◆ getVolume()

int getVolume ( )
static

Returns the overall audio volume from 0 (silence) to 100 (full volume).

The default volume is 100.

◆ pause()

void pause ( )
static

Pauses playing the sound, if it is playing.

If paused, calling play() again will unpause.

◆ play()

void play ( )

Starts playing the sound.

This call returns immediately without waiting for the sound to finish.

◆ playSound()

void playSound ( string   filename)
static

Starts playing the sound if not playing, or unpauses if paused.

This call returns immediately without waiting for the sound to finish.

◆ setVolume()

void setVolume ( int  volume)
static

Sets the overall audio volume from 0 (silence) to 100 (full volume).

The default volume is 100.

◆ stop()

void stop ( )
static

Stops playing the sound, if it is playing.