source: trunk/src/3rdparty/phonon/mmf/audioplayer.cpp

Last change on this file was 846, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

  • Property svn:eol-style set to native
File size: 7.5 KB
Line 
1/* This file is part of the KDE project.
2
3Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4
5This library is free software: you can redistribute it and/or modify
6it under the terms of the GNU Lesser General Public License as published by
7the Free Software Foundation, either version 2.1 or 3 of the License.
8
9This library is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU Lesser General Public License for more details.
13
14You should have received a copy of the GNU Lesser General Public License
15along with this library. If not, see <http://www.gnu.org/licenses/>.
16
17*/
18
19#include <QDir>
20#include <QUrl>
21
22#include "audioplayer.h"
23#include "utils.h"
24
25QT_BEGIN_NAMESPACE
26
27using namespace Phonon;
28using namespace Phonon::MMF;
29
30/*! \class MMF::AudioPlayer
31 \internal
32*/
33
34//-----------------------------------------------------------------------------
35// Constructor / destructor
36//-----------------------------------------------------------------------------
37
38MMF::AudioPlayer::AudioPlayer(MediaObject *parent, const AbstractPlayer *player)
39 : AbstractMediaPlayer(parent, player)
40 , m_totalTime(0)
41{
42 construct();
43}
44
45void MMF::AudioPlayer::construct()
46{
47 TRACE_CONTEXT(AudioPlayer::AudioPlayer, EAudioApi);
48 TRACE_ENTRY_0();
49
50 NativePlayer *player = 0;
51 QT_TRAP_THROWING(player = NativePlayer::NewL(*this, 0, EMdaPriorityPreferenceNone));
52 m_player.reset(player);
53 m_player->RegisterForAudioLoadingNotification(*this);
54
55 TRACE_EXIT_0();
56}
57
58MMF::AudioPlayer::~AudioPlayer()
59{
60 TRACE_CONTEXT(AudioPlayer::~AudioPlayer, EAudioApi);
61 TRACE_ENTRY_0();
62
63 TRACE_EXIT_0();
64}
65
66MMF::AudioPlayer::NativePlayer *MMF::AudioPlayer::nativePlayer() const
67{
68 return m_player.data();
69}
70
71//-----------------------------------------------------------------------------
72// Public API
73//-----------------------------------------------------------------------------
74
75void MMF::AudioPlayer::doPlay()
76{
77 m_player->Play();
78}
79
80void MMF::AudioPlayer::doPause()
81{
82 m_player->Pause();
83}
84
85void MMF::AudioPlayer::doStop()
86{
87 m_player->Stop();
88}
89
90void MMF::AudioPlayer::doSeek(qint64 ms)
91{
92 m_player->SetPosition(TTimeIntervalMicroSeconds(ms * 1000));
93}
94
95int MMF::AudioPlayer::setDeviceVolume(int mmfVolume)
96{
97 /* In SDK 3.1, SetVolume() returns void. If we're compiling against
98 * 3.1, we handle it with ifdefs. However, if we compile against a later
99 * SDK but are _running_ against 3.1, we avoid returning from an undefined
100 * stack by doing a runtime check of the SDK version. */
101#if !defined(__SERIES60_31__)
102 const int err = m_player->SetVolume(mmfVolume);
103 if (QSysInfo::s60Version() >= QSysInfo::SV_S60_3_2)
104 return err;
105 else
106 return KErrNone;
107 #else
108 m_player->SetVolume(mmfVolume);
109 return KErrNone;
110#endif
111}
112
113int MMF::AudioPlayer::openFile(const QString &fileName)
114{
115 const QHBufC nativeFileName(QDir::toNativeSeparators(fileName));
116 TRAPD(err, m_player->OpenFileL(*nativeFileName));
117 return err;
118}
119
120int MMF::AudioPlayer::openFile(RFile& file)
121{
122 TRAPD(err, m_player->OpenFileL(file));
123
124#ifdef QT_PHONON_MMF_AUDIO_DRM
125 if (KErrNone == err) {
126 // There appears to be a bug in the CDrmPlayerUtility implementation (at least
127 // in S60 5.x) whereby the player does not check whether the loading observer
128 // pointer is null before dereferencing it. Therefore we must register for
129 // loading notification, even though we do nothing in the callback functions.
130 m_player->RegisterForAudioLoadingNotification(*this);
131 }
132#endif
133
134 return err;
135}
136
137int MMF::AudioPlayer::openUrl(const QString& /*url*/, int /*iap*/)
138{
139 // Streaming playback is generally not supported by the implementation
140 // of the audio player API, so we use CVideoPlayerUtility for both
141 // audio and video streaming.
142 Utils::panic(AudioUtilityUrlNotSupported);
143
144 // Silence warning
145 return 0;
146}
147
148int MMF::AudioPlayer::openDescriptor(const TDesC8 &des)
149{
150 TRAPD(err, m_player->OpenDesL(des));
151 return err;
152}
153
154int MMF::AudioPlayer::bufferStatus() const
155{
156 int result = 0;
157 TRAP_IGNORE(m_player->GetAudioLoadingProgressL(result));
158 return result;
159}
160
161void MMF::AudioPlayer::doClose()
162{
163 m_player->Close();
164}
165
166bool MMF::AudioPlayer::hasVideo() const
167{
168 return false;
169}
170
171qint64 MMF::AudioPlayer::getCurrentTime() const
172{
173 TRACE_CONTEXT(AudioPlayer::getCurrentTime, EAudioApi);
174
175 TTimeIntervalMicroSeconds us;
176 const TInt err = m_player->GetPosition(us);
177
178 qint64 result = 0;
179
180 if (KErrNone == err) {
181 result = toMilliSeconds(us);
182 } else {
183 TRACE("GetPosition err %d", err);
184
185 // If we don't cast away constness here, we simply have to ignore
186 // the error.
187 const_cast<AudioPlayer*>(this)->setError(tr("Getting position failed"), err);
188 }
189
190 return result;
191}
192
193qint64 MMF::AudioPlayer::totalTime() const
194{
195 return m_totalTime;
196}
197
198
199//-----------------------------------------------------------------------------
200// Symbian multimedia client observer callbacks
201//-----------------------------------------------------------------------------
202
203#ifdef QT_PHONON_MMF_AUDIO_DRM
204void MMF::AudioPlayer::MdapcInitComplete(TInt aError,
205 const TTimeIntervalMicroSeconds &)
206#else
207void MMF::AudioPlayer::MapcInitComplete(TInt aError,
208 const TTimeIntervalMicroSeconds &)
209#endif
210{
211 TRACE_CONTEXT(AudioPlayer::MapcInitComplete, EAudioInternal);
212 TRACE_ENTRY("state %d error %d", state(), aError);
213
214 __ASSERT_ALWAYS(LoadingState == state() ||
215 progressiveDownloadStalled() && BufferingState == state(),
216 Utils::panic(InvalidStatePanic));
217
218 if (KErrNone == aError) {
219 maxVolumeChanged(m_player->MaxVolume());
220 m_totalTime = toMilliSeconds(m_player->Duration());
221 emit totalTimeChanged(m_totalTime);
222 }
223
224 loadingComplete(aError);
225
226 TRACE_EXIT_0();
227}
228
229#ifdef QT_PHONON_MMF_AUDIO_DRM
230void MMF::AudioPlayer::MdapcPlayComplete(TInt aError)
231#else
232void MMF::AudioPlayer::MapcPlayComplete(TInt aError)
233#endif
234{
235 TRACE_CONTEXT(AudioPlayer::MapcPlayComplete, EAudioInternal);
236 TRACE_ENTRY("state %d error %d", state(), aError);
237
238 // Call base class function which handles end of playback for both
239 // audio and video clips.
240 playbackComplete(aError);
241
242 TRACE_EXIT_0();
243}
244
245#ifdef QT_PHONON_MMF_AUDIO_DRM
246void MMF::AudioPlayer::MaloLoadingStarted()
247{
248
249}
250
251void MMF::AudioPlayer::MaloLoadingComplete()
252{
253
254}
255#endif // QT_PHONON_MMF_AUDIO_DRM
256
257
258//-----------------------------------------------------------------------------
259// MAudioLoadingObserver callbacks
260//-----------------------------------------------------------------------------
261
262void MMF::AudioPlayer::MaloLoadingStarted()
263{
264 bufferingStarted();
265}
266
267void MMF::AudioPlayer::MaloLoadingComplete()
268{
269 bufferingComplete();
270}
271
272
273//-----------------------------------------------------------------------------
274// Private functions
275//-----------------------------------------------------------------------------
276
277int MMF::AudioPlayer::numberOfMetaDataEntries() const
278{
279 int numberOfEntries = 0;
280 m_player->GetNumberOfMetaDataEntries(numberOfEntries); // ignoring return code
281 return numberOfEntries;
282}
283
284QPair<QString, QString> MMF::AudioPlayer::metaDataEntry(int index) const
285{
286 CMMFMetaDataEntry *entry = 0;
287 QT_TRAP_THROWING(entry = m_player->GetMetaDataEntryL(index));
288 return QPair<QString, QString>(qt_TDesC2QString(entry->Name()), qt_TDesC2QString(entry->Value()));
289}
290
291
292QT_END_NAMESPACE
293
Note: See TracBrowser for help on using the repository browser.