source: trunk/src/gui/kernel/qsound.cpp@ 765

Last change on this file since 765 was 651, checked in by Dmitry A. Kuminov, 16 years ago

trunk: Merged in qt 4.6.2 sources.

File size: 10.0 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the QtGui module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include "qsound.h"
43
44#ifndef QT_NO_SOUND
45
46#include "qlist.h"
47#include <private/qobject_p.h>
48#include "qsound_p.h"
49
50QT_BEGIN_NAMESPACE
51
52static QList<QAuServer*> *servers=0;
53
54QAuServer::QAuServer(QObject* parent)
55 : QObject(parent)
56{
57 if (!servers)
58 servers = new QList<QAuServer*>;
59 servers->prepend(this);
60}
61
62QAuServer::~QAuServer()
63{
64 servers->removeAll(this);
65 if (servers->count() == 0) {
66 delete servers;
67 servers = 0;
68 }
69}
70
71void QAuServer::play(const QString& filename)
72{
73 QSound s(filename);
74 play(&s);
75}
76
77extern QAuServer* qt_new_audio_server();
78
79static QAuServer& server()
80{
81 if (!servers) qt_new_audio_server();
82 return *servers->first();
83}
84
85class QSoundPrivate : public QObjectPrivate
86{
87public:
88 QSoundPrivate(const QString& fname)
89 : filename(fname), server(0), bucket(0), looprem(0), looptotal(1)
90 {
91 }
92
93 ~QSoundPrivate()
94 {
95 delete bucket;
96 }
97
98 QString filename;
99 QAuServer* server;
100 QAuBucket* bucket;
101 int looprem;
102 int looptotal;
103};
104
105/*!
106 \class QSound
107 \brief The QSound class provides access to the platform audio facilities.
108
109 \ingroup multimedia
110
111
112 Qt provides the most commonly required audio operation in GUI
113 applications: asynchronously playing a sound file. This is most
114 easily accomplished using the static play() function:
115
116 \snippet doc/src/snippets/code/src_gui_kernel_qsound.cpp 0
117
118 Alternatively, create a QSound object from the sound file first
119 and then call the play() slot:
120
121 \snippet doc/src/snippets/code/src_gui_kernel_qsound.cpp 1
122
123 Once created a QSound object can be queried for its fileName() and
124 total number of loops() (i.e. the number of times the sound will
125 play). The number of repetitions can be altered using the
126 setLoops() function. While playing the sound, the loopsRemaining()
127 function returns the remaining number of repetitions. Use the
128 isFinished() function to determine whether the sound has finished
129 playing.
130