SGL
gsound.h
1 /*
2  * File: gsound.h
3  * --------------
4  * This file defines a class that represents a sound.
5  *
6  * @version 2021/04/03
7  * - removed dependencies
8  * - renamed to GSound
9  * @version 2018/10/23
10  * - reimplemented in C++ using QSound class
11  * @version 2018/09/25
12  * - added doc comments for new documentation generation
13  */
14 
15 
16 #ifndef _gsound_h
17 #define _gsound_h
18 
19 #include <string>
20 #include <QMediaPlayer>
21 
41 class GSound {
42 public:
47  static long getDuration();
48 
53  static int getVolume();
54 
59  static void pause();
60 
65  static void playSound(const string& filename);
66 
71  static void setVolume(int volume);
72 
76  static void stop();
77 
78 
79  // begin old object-oriented interface (kept for backward compatibility)
80 
85  GSound(const string& filename);
86 
90  virtual ~GSound();
91 
96  void play();
97 
98 private:
99  static QMediaPlayer* _qmediaPlayer;
100 
101  static void initialize();
102 
103  string _filename;
104 };
105 
106 #endif // _gsound_h
static long getDuration()
Returns the duration of the sound clip that is currently playing.
Definition: gsound.cpp:26
static void stop()
Stops playing the sound, if it is playing.
Definition: gsound.cpp:64
static void pause()
Pauses playing the sound, if it is playing.
Definition: gsound.cpp:46
static void setVolume(int volume)
Sets the overall audio volume from 0 (silence) to 100 (full volume).
Definition: gsound.cpp:69
virtual ~GSound()
Frees the memory associated with the sound.
Definition: gsound.cpp:80
This class encapsulates a sound file.
Definition: gsound.h:41
static void playSound(string filename)
Starts playing the sound if not playing, or unpauses if paused.
Definition: gsound.cpp:51
static int getVolume()
Returns the overall audio volume from 0 (silence) to 100 (full volume).
Definition: gsound.cpp:31
GSound(string filename)
Creates a Sound object by reading in the contents of the specified file or URL.
Definition: gsound.cpp:75
void play()
Starts playing the sound.
Definition: gsound.cpp:84