]>
Commit | Line | Data |
---|---|---|
23324ae1 FM |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: sound.h | |
e54c96f1 | 3 | // Purpose: interface of wxSound |
23324ae1 | 4 | // Author: wxWidgets team |
526954c5 | 5 | // Licence: wxWindows licence |
23324ae1 FM |
6 | ///////////////////////////////////////////////////////////////////////////// |
7 | ||
e4476836 RD |
8 | |
9 | #define wxSOUND_SYNC 0 | |
10 | #define wxSOUND_ASYNC 1 | |
11 | #define wxSOUND_LOOP 2 | |
12 | ||
13 | ||
23324ae1 FM |
14 | /** |
15 | @class wxSound | |
7c913512 | 16 | |
23324ae1 | 17 | This class represents a short sound (loaded from Windows WAV file), that |
e725ba4f FM |
18 | can be stored in memory and played. |
19 | ||
20 | Currently this class is implemented on Windows and Unix (and uses either | |
21 | Open Sound System or Simple DirectMedia Layer). | |
7c913512 | 22 | |
23324ae1 | 23 | @library{wxadv} |
3c99e2fd | 24 | @category{media} |
23324ae1 FM |
25 | */ |
26 | class wxSound : public wxObject | |
27 | { | |
28 | public: | |
e725ba4f FM |
29 | /** |
30 | Default ctor. | |
31 | */ | |
32 | wxSound(); | |
33 | ||
23324ae1 FM |
34 | /** |
35 | Constructs a wave object from a file or, under Windows, from a Windows | |
e725ba4f | 36 | resource. Call IsOk() to determine whether this succeeded. |
3c4f71cc | 37 | |
7c913512 | 38 | @param fileName |
4cc4bfaf | 39 | The filename or Windows resource. |
7c913512 | 40 | @param isResource |
4cc4bfaf | 41 | @true if fileName is a resource, @false if it is a filename. |
23324ae1 | 42 | */ |
4cc4bfaf | 43 | wxSound(const wxString& fileName, bool isResource = false); |
23324ae1 FM |
44 | |
45 | /** | |
c559c4b3 VZ |
46 | Constructs a wave object from in-memory data. |
47 | ||
48 | @param size | |
49 | Size of the buffer pointer to by @a data. | |
50 | @param data | |
51 | The buffer containing the sound data in WAV format. | |
52 | */ | |
53 | wxSound(size_t size, const void* data); | |
54 | ||
55 | /** | |
23324ae1 FM |
56 | Destroys the wxSound object. |
57 | */ | |
adaaa686 | 58 | virtual ~wxSound(); |
23324ae1 FM |
59 | |
60 | /** | |
61 | Constructs a wave object from a file or resource. | |
3c4f71cc | 62 | |
7c913512 | 63 | @param fileName |
4cc4bfaf | 64 | The filename or Windows resource. |
7c913512 | 65 | @param isResource |
4cc4bfaf | 66 | @true if fileName is a resource, @false if it is a filename. |
3c4f71cc | 67 | |
d29a9a8a | 68 | @return @true if the call was successful, @false otherwise. |
23324ae1 | 69 | */ |
4cc4bfaf | 70 | bool Create(const wxString& fileName, bool isResource = false); |
23324ae1 | 71 | |
e4476836 RD |
72 | /** |
73 | Constructs a wave object from in-memory data. | |
74 | ||
75 | @param size | |
76 | Size of the buffer pointer to by @a data. | |
77 | @param data | |
78 | The buffer containing the sound data in WAV format. | |
79 | */ | |
80 | bool Create(size_t size, const void* data); | |
81 | ||
23324ae1 FM |
82 | /** |
83 | Returns @true if the object contains a successfully loaded file or resource, | |
84 | @false otherwise. | |
85 | */ | |
328f5751 | 86 | bool IsOk() const; |
23324ae1 FM |
87 | |
88 | /** | |
89 | Returns @true if a sound is played at the moment. | |
f85d2074 VZ |
90 | |
91 | This method is currently not available under Windows and may not be | |
92 | always implemented in Unix ports depending on the compilation options | |
93 | used (in this case it just always returns @false). | |
94 | ||
95 | @onlyfor{wxgtk,wxosx} | |
23324ae1 | 96 | */ |
57bf907d | 97 | static bool IsPlaying(); |
23324ae1 FM |
98 | |
99 | //@{ | |
100 | /** | |
101 | Plays the sound file. If another sound is playing, it will be interrupted. | |
e725ba4f | 102 | |
23324ae1 | 103 | Returns @true on success, @false otherwise. Note that in general it is |
e725ba4f FM |
104 | possible to delete the object which is being asynchronously played any time |
105 | after calling this function and the sound would continue playing, however this | |
23324ae1 | 106 | currently doesn't work under Windows for sound objects loaded from memory data. |
3c4f71cc | 107 | |
e725ba4f FM |
108 | The possible values for @a flags are: |
109 | - wxSOUND_SYNC: @c Play will block and wait until the sound is replayed. | |
110 | - wxSOUND_ASYNC: Sound is played asynchronously, @c Play returns immediately. | |
111 | - wxSOUND_ASYNC|wxSOUND_LOOP: Sound is played asynchronously and loops | |
112 | until another sound is played, Stop() is | |
113 | called or the program terminates. | |
3c4f71cc | 114 | |
23324ae1 | 115 | The static form is shorthand for this code: |
e725ba4f FM |
116 | @code |
117 | wxSound(filename).Play(flags); | |
118 | @endcode | |
23324ae1 | 119 | */ |
e725ba4f FM |
120 | bool Play(unsigned flags = wxSOUND_ASYNC) const; |
121 | static bool Play(const wxString& filename, | |
122 | unsigned flags = wxSOUND_ASYNC); | |
23324ae1 FM |
123 | //@} |
124 | ||
125 | /** | |
126 | If a sound is played, this function stops it. | |
127 | */ | |
128 | static void Stop(); | |
129 | }; | |
e54c96f1 | 130 |