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