0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 |
** All rights reserved.
|
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
6 |
**
|
|
7 |
** This file is part of the QtGui of the Qt Toolkit.
|
|
8 |
**
|
|
9 |
** $QT_BEGIN_LICENSE:LGPL$
|
|
10 |
** No Commercial Usage
|
|
11 |
** This file contains pre-release code and may not be distributed.
|
|
12 |
** You may use this file in accordance with the terms and conditions
|
|
13 |
** contained in the Technology Preview License Agreement accompanying
|
|
14 |
** this package.
|
|
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 |
** If you have questions regarding the use of this file, please contact
|
|
29 |
** Nokia at qt-info@nokia.com.
|
|
30 |
**
|
|
31 |
**
|
|
32 |
**
|
|
33 |
**
|
|
34 |
**
|
|
35 |
**
|
|
36 |
**
|
|
37 |
**
|
|
38 |
** $QT_END_LICENSE$
|
|
39 |
**
|
|
40 |
****************************************************************************/
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
#ifndef QT_NO_SOUND
|
|
45 |
|
|
46 |
#include "qdir.h"
|
|
47 |
#include "qapplication.h"
|
|
48 |
#include "qsound.h"
|
|
49 |
#include "qsound_p.h"
|
|
50 |
#include "qfileinfo.h"
|
|
51 |
#include <private/qcore_symbian_p.h>
|
|
52 |
|
|
53 |
#include <e32std.h>
|
|
54 |
#include <MdaAudioSamplePlayer.h>
|
|
55 |
|
|
56 |
QT_BEGIN_NAMESPACE
|
|
57 |
|
|
58 |
class QAuServerS60;
|
|
59 |
|
|
60 |
class QAuBucketS60 : public QAuBucket, public MMdaAudioPlayerCallback
|
|
61 |
{
|
|
62 |
public:
|
|
63 |
QAuBucketS60( QAuServerS60 *server, QSound *sound);
|
|
64 |
~QAuBucketS60();
|
|
65 |
|
|
66 |
void play();
|
|
67 |
void stop();
|
|
68 |
|
|
69 |
inline QSound* sound() const { return m_sound; }
|
|
70 |
|
|
71 |
public: // from MMdaAudioPlayerCallback
|
|
72 |
void MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds& aDuration);
|
|
73 |
void MapcPlayComplete(TInt aError);
|
|
74 |
|
|
75 |
private:
|
|
76 |
QSound *m_sound;
|
|
77 |
QAuServerS60 *m_server;
|
|
78 |
bool m_prepared;
|
|
79 |
bool m_playCalled;
|
|
80 |
CMdaAudioPlayerUtility* m_playUtility;
|
|
81 |
};
|
|
82 |
|
|
83 |
|
|
84 |
class QAuServerS60 : public QAuServer
|
|
85 |
{
|
|
86 |
public:
|
|
87 |
QAuServerS60( QObject* parent );
|
|
88 |
|
|
89 |
void init( QSound* s )
|
|
90 |
{
|
|
91 |
QAuBucketS60 *bucket = new QAuBucketS60( this, s );
|
|
92 |
setBucket( s, bucket );
|
|
93 |
}
|
|
94 |
|
|
95 |
void play( QSound* s )
|
|
96 |
{
|
|
97 |
bucket( s )->play();
|
|
98 |
}
|
|
99 |
|
|
100 |
void stop( QSound* s )
|
|
101 |
{
|
|
102 |
bucket( s )->stop();
|
|
103 |
}
|
|
104 |
|
|
105 |
bool okay() { return true; }
|
|
106 |
|
|
107 |
protected:
|
|
108 |
void playCompleted(QAuBucketS60* bucket, int error)
|
|
109 |
{
|
|
110 |
QSound *sound = bucket->sound();
|
|
111 |
if(!error) {
|
|
112 |
// We need to handle repeats by ourselves, since with Symbian API we don't
|
|
113 |
// know how many loops have been played when user asks it
|
|
114 |
if( decLoop( sound ) ) {
|
|
115 |
play( sound );
|
|
116 |
}
|
|
117 |
} else {
|
|
118 |
// We don't have a way to inform about errors -> just decrement loops
|
|
119 |
// in order that QSound::isFinished will return true;
|
|
120 |
while(decLoop(sound)) {}
|
|
121 |
}
|
|
122 |
}
|
|
123 |
|
|
124 |
protected:
|
|
125 |
QAuBucketS60* bucket( QSound *s )
|
|
126 |
{
|
|
127 |
return (QAuBucketS60*)QAuServer::bucket( s );
|
|
128 |
}
|
|
129 |
|
|
130 |
friend class QAuBucketS60;
|
|
131 |
|
|
132 |
};
|
|
133 |
|
|
134 |
QAuServerS60::QAuServerS60(QObject* parent) :
|
|
135 |
QAuServer(parent)
|
|
136 |
{
|
|
137 |
setObjectName(QLatin1String("QAuServerS60"));
|
|
138 |
}
|
|
139 |
|
|
140 |
|
|
141 |
QAuServer* qt_new_audio_server()
|
|
142 |
{
|
|
143 |
return new QAuServerS60(qApp);
|
|
144 |
}
|
|
145 |
|
|
146 |
QAuBucketS60::QAuBucketS60( QAuServerS60 *server, QSound *sound )
|
|
147 |
: m_sound( sound ), m_server( server ), m_prepared(false), m_playCalled(false)
|
|
148 |
{
|
|
149 |
QString filepath = QFileInfo( m_sound->fileName() ).absoluteFilePath();
|
|
150 |
filepath = QDir::toNativeSeparators(filepath);
|
|
151 |
TPtrC filepathPtr(qt_QString2TPtrC(filepath));
|
|
152 |
TRAPD(err, m_playUtility = CMdaAudioPlayerUtility::NewL(*this);
|
|
153 |
m_playUtility->OpenFileL(filepathPtr));
|
|
154 |
if(err){
|
|
155 |
m_server->playCompleted(this, err);
|
|
156 |
}
|
|
157 |
}
|
|
158 |
|
|
159 |
void QAuBucketS60::play()
|
|
160 |
{
|
|
161 |
if(m_prepared) {
|
|
162 |
// OpenFileL call is completed we can start playing immediately
|
|
163 |
m_playUtility->Play();
|
|
164 |
} else {
|
|
165 |
m_playCalled = true;
|
|
166 |
}
|
|
167 |
|
|
168 |
}
|
|
169 |
|
|
170 |
void QAuBucketS60::stop()
|
|
171 |
{
|
|
172 |
m_playCalled = false;
|
|
173 |
m_playUtility->Stop();
|
|
174 |
}
|
|
175 |
|
|
176 |
void QAuBucketS60::MapcPlayComplete(TInt aError)
|
|
177 |
{
|
|
178 |
m_server->playCompleted(this, aError);
|
|
179 |
}
|
|
180 |
|
|
181 |
void QAuBucketS60::MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds& /*aDuration*/)
|
|
182 |
{
|
|
183 |
if(aError) {
|
|
184 |
m_server->playCompleted(this, aError);
|
|
185 |
} else {
|
|
186 |
m_prepared = true;
|
|
187 |
if(m_playCalled){
|
|
188 |
play();
|
|
189 |
}
|
|
190 |
}
|
|
191 |
}
|
|
192 |
|
|
193 |
QAuBucketS60::~QAuBucketS60()
|
|
194 |
{
|
|
195 |
if(m_playUtility){
|
|
196 |
m_playUtility->Stop();
|
|
197 |
m_playUtility->Close();
|
|
198 |
}
|
|
199 |
|
|
200 |
delete m_playUtility;
|
|
201 |
}
|
|
202 |
|
|
203 |
|
|
204 |
#endif // QT_NO_SOUND
|
|
205 |
|
|
206 |
QT_END_NAMESPACE
|