1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
---|
2 | <!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/examples/sound/sound.doc:1 -->
|
---|
3 | <html>
|
---|
4 | <head>
|
---|
5 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
---|
6 | <title>Sound Example</title>
|
---|
7 | <style type="text/css"><!--
|
---|
8 | fn { margin-left: 1cm; text-indent: -1cm; }
|
---|
9 | a:link { color: #004faf; text-decoration: none }
|
---|
10 | a:visited { color: #672967; text-decoration: none }
|
---|
11 | body { background: #ffffff; color: black; }
|
---|
12 | --></style>
|
---|
13 | </head>
|
---|
14 | <body>
|
---|
15 |
|
---|
16 | <table border="0" cellpadding="0" cellspacing="0" width="100%">
|
---|
17 | <tr bgcolor="#E5E5E5">
|
---|
18 | <td valign=center>
|
---|
19 | <a href="index.html">
|
---|
20 | <font color="#004faf">Home</font></a>
|
---|
21 | | <a href="classes.html">
|
---|
22 | <font color="#004faf">All Classes</font></a>
|
---|
23 | | <a href="mainclasses.html">
|
---|
24 | <font color="#004faf">Main Classes</font></a>
|
---|
25 | | <a href="annotated.html">
|
---|
26 | <font color="#004faf">Annotated</font></a>
|
---|
27 | | <a href="groups.html">
|
---|
28 | <font color="#004faf">Grouped Classes</font></a>
|
---|
29 | | <a href="functions.html">
|
---|
30 | <font color="#004faf">Functions</font></a>
|
---|
31 | </td>
|
---|
32 | <td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>Sound Example</h1>
|
---|
33 |
|
---|
34 |
|
---|
35 | <p>
|
---|
36 | This example shows how easy it is to play sounds, e.g. .WAV files,
|
---|
37 | if your machine is set up to play audio.
|
---|
38 | <p> <hr>
|
---|
39 | <p> Header file:
|
---|
40 | <p> <pre>/****************************************************************************
|
---|
41 | ** $Id: sound-example.html 2051 2007-02-21 10:04:20Z chehrlic $
|
---|
42 | **
|
---|
43 | ** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
|
---|
44 | **
|
---|
45 | ** This file is part of an example program for Qt. This example
|
---|
46 | ** program may be used, distributed and modified without limitation.
|
---|
47 | **
|
---|
48 | *****************************************************************************/
|
---|
49 | #ifndef PLAY_H
|
---|
50 | #define PLAY_H
|
---|
51 |
|
---|
52 | #include "qsound.h"
|
---|
53 | #include <<a href="qmainwindow-h.html">qmainwindow.h</a>>
|
---|
54 |
|
---|
55 | class SoundPlayer : public <a href="qmainwindow.html">QMainWindow</a> {
|
---|
56 | <a href="metaobjects.html#Q_OBJECT">Q_OBJECT</a>
|
---|
57 | public:
|
---|
58 | SoundPlayer();
|
---|
59 |
|
---|
60 | public slots:
|
---|
61 | void doPlay1();
|
---|
62 | void doPlay2();
|
---|
63 | void doPlay3();
|
---|
64 | void doPlay4();
|
---|
65 | void doPlay34();
|
---|
66 | void doPlay1234();
|
---|
67 |
|
---|
68 | private:
|
---|
69 | <a href="qsound.html">QSound</a> bucket3;
|
---|
70 | <a href="qsound.html">QSound</a> bucket4;
|
---|
71 | };
|
---|
72 |
|
---|
73 | #endif
|
---|
74 | </pre>
|
---|
75 |
|
---|
76 | <p> <hr>
|
---|
77 | <p> Implementation:
|
---|
78 | <p> <pre>/****************************************************************************
|
---|
79 | ** $Id: sound-example.html 2051 2007-02-21 10:04:20Z chehrlic $
|
---|
80 | **
|
---|
81 | ** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
|
---|
82 | **
|
---|
83 | ** This file is part of an example program for Qt. This example
|
---|
84 | ** program may be used, distributed and modified without limitation.
|
---|
85 | **
|
---|
86 | *****************************************************************************/
|
---|
87 | //
|
---|
88 | // Very simple example of QSound::play(filename)
|
---|
89 | //
|
---|
90 | // 99% of this program is just boilerplate Qt code to put up a nice
|
---|
91 | // window so you think something special is happening.
|
---|
92 | //
|
---|
93 |
|
---|
94 | #include "sound.h"
|
---|
95 | #include <<a href="qapplication-h.html">qapplication.h</a>>
|
---|
96 | #include <<a href="qmessagebox-h.html">qmessagebox.h</a>>
|
---|
97 | #include <<a href="qmenubar-h.html">qmenubar.h</a>>
|
---|
98 |
|
---|
99 | <a name="f581"></a>SoundPlayer::SoundPlayer() :
|
---|
100 | <a href="qmainwindow.html">QMainWindow</a>(),
|
---|
101 | bucket3("sounds/3.wav"),
|
---|
102 | bucket4("sounds/4.wav")
|
---|
103 | {
|
---|
104 | if (!QSound::isAvailable()) {
|
---|
105 | // Bail out. Programs in which sound is not critical
|
---|
106 | // could just silently (hehe) ignore the lack of a server.
|
---|
107 | //
|
---|
108 | <a name="x2812"></a> QMessageBox::<a href="qmessagebox.html#warning">warning</a>(this,"No Sound",
|
---|
109 | "<p><b>Sorry, you are not running the Network Audio System.</b>"
|
---|
110 | "<p>If you have the `au' command, run it in the background before this program. "
|
---|
111 | "The latest release of the Network Audio System can be obtained from:"
|
---|
112 | "<pre>\n"
|
---|
113 | " &nbsp;\n"
|
---|
114 | " ftp.ncd.com:/pub/ncd/technology/src/nas\n"
|
---|
115 | " ftp.x.org:/contrib/audio/nas\n"
|
---|
116 | "</pre>"
|
---|
117 | "<p>Release 1.2 of NAS is also included with the X11R6"
|
---|
118 | "contrib distribution."
|
---|
119 | "<p>After installing NAS, you will then need to reconfigure Qt with NAS sound support");
|
---|
120 | }
|
---|
121 |
|
---|
122 | <a href="qpopupmenu.html">QPopupMenu</a> *file = new <a href="qpopupmenu.html">QPopupMenu</a>;
|
---|
123 | <a name="x2810"></a> file-><a href="qmenudata.html#insertItem">insertItem</a>("Play &1", this, SLOT(doPlay1()), CTRL+Key_1);
|
---|
124 | file-><a href="qmenudata.html#insertItem">insertItem</a>("Play &2", this, SLOT(doPlay2()), CTRL+Key_2);
|
---|
125 | file-><a href="qmenudata.html#insertItem">insertItem</a>("Play from bucket &3", this, SLOT(doPlay3()), CTRL+Key_3);
|
---|
126 | file-><a href="qmenudata.html#insertItem">insertItem</a>("Play from bucket &4", this, SLOT(doPlay4()), CTRL+Key_4);
|
---|
127 | <a name="x2811"></a> file-><a href="qmenudata.html#insertSeparator">insertSeparator</a>();
|
---|
128 | file-><a href="qmenudata.html#insertItem">insertItem</a>("Play 3 and 4 together", this, SLOT(doPlay34()));
|
---|
129 | file-><a href="qmenudata.html#insertItem">insertItem</a>("Play all together", this, SLOT(doPlay1234()));
|
---|
130 | file-><a href="qmenudata.html#insertSeparator">insertSeparator</a>();
|
---|
131 | file-><a href="qmenudata.html#insertItem">insertItem</a>("E&xit", qApp, SLOT(<a href="qapplication.html#quit">quit</a>()));
|
---|
132 | <a href="qmainwindow.html#menuBar">menuBar</a>()->insertItem("&File", file);
|
---|
133 | }
|
---|
134 |
|
---|
135 | void <a name="f582"></a>SoundPlayer::doPlay1()
|
---|
136 | {
|
---|
137 | <a name="x2813"></a> QSound::<a href="qsound.html#play">play</a>("sounds/1.wav");
|
---|
138 | }
|
---|
139 |
|
---|
140 | void <a name="f583"></a>SoundPlayer::doPlay2()
|
---|
141 | {
|
---|
142 | QSound::<a href="qsound.html#play">play</a>("sounds/2.wav");
|
---|
143 | }
|
---|
144 |
|
---|
145 | void <a name="f584"></a>SoundPlayer::doPlay3()
|
---|
146 | {
|
---|
147 | bucket3.play();
|
---|
148 | }
|
---|
149 |
|
---|
150 | void <a name="f585"></a>SoundPlayer::doPlay4()
|
---|
151 | {
|
---|
152 | bucket4.play();
|
---|
153 | }
|
---|
154 |
|
---|
155 | void <a name="f586"></a>SoundPlayer::doPlay34()
|
---|
156 | {
|
---|
157 | // Some sound platforms will only play one sound at a time
|
---|
158 | bucket3.play();
|
---|
159 | bucket4.play();
|
---|
160 | }
|
---|
161 |
|
---|
162 | void <a name="f587"></a>SoundPlayer::doPlay1234()
|
---|
163 | {
|
---|
164 | // Some sound platforms will only play one sound at a time
|
---|
165 | QSound::<a href="qsound.html#play">play</a>("sounds/1.wav");
|
---|
166 | QSound::<a href="qsound.html#play">play</a>("sounds/2.wav");
|
---|
167 | bucket3.play();
|
---|
168 | bucket4.play();
|
---|
169 | }
|
---|
170 |
|
---|
171 | int main(int argc, char** argv)
|
---|
172 | {
|
---|
173 | <a href="qapplication.html">QApplication</a> app(argc,argv);
|
---|
174 | SoundPlayer sp;
|
---|
175 | app.<a href="qapplication.html#setMainWidget">setMainWidget</a>(&sp);
|
---|
176 | sp.<a href="qwidget.html#setCaption">setCaption</a>("Qt Example - Sounds");
|
---|
177 | sp.<a href="qwidget.html#show">show</a>();
|
---|
178 | return app.<a href="qapplication.html#exec">exec</a>();
|
---|
179 | }
|
---|
180 |
|
---|
181 | </pre>
|
---|
182 |
|
---|
183 | <p> <p>See also <a href="examples.html">Examples</a>.
|
---|
184 |
|
---|
185 | <!-- eof -->
|
---|
186 | <p><address><hr><div align=center>
|
---|
187 | <table width=100% cellspacing=0 border=0><tr>
|
---|
188 | <td>Copyright © 2007
|
---|
189 | <a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
|
---|
190 | <td align=right><div align=right>Qt 3.3.8</div>
|
---|
191 | </table></div></address></body>
|
---|
192 | </html>
|
---|