1
/* This file is part of the KDE project.
3
Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
5
This library is free software: you can redistribute it and/or modify
6
it under the terms of the GNU Lesser General Public License as published by
7
the Free Software Foundation, either version 2.1 or 3 of the License.
9
This library is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU Lesser General Public License for more details.
14
You should have received a copy of the GNU Lesser General Public License
15
along with this library. If not, see <http://www.gnu.org/licenses/>.
21
#include "audioplayer.h"
26
using namespace Phonon;
27
using namespace Phonon::MMF;
29
/*! \class MMF::AudioPlayer
33
//-----------------------------------------------------------------------------
34
// Constructor / destructor
35
//-----------------------------------------------------------------------------
37
MMF::AudioPlayer::AudioPlayer() : m_player(0)
42
MMF::AudioPlayer::AudioPlayer(const AbstractPlayer& player)
43
: AbstractMediaPlayer(player)
49
void MMF::AudioPlayer::construct()
51
TRACE_CONTEXT(AudioPlayer::AudioPlayer, EAudioApi);
54
TRAPD(err, m_player = CPlayerType::NewL(*this, 0, EMdaPriorityPreferenceNone));
55
if (KErrNone != err) {
56
changeState(ErrorState);
62
MMF::AudioPlayer::~AudioPlayer()
64
TRACE_CONTEXT(AudioPlayer::~AudioPlayer, EAudioApi);
72
//-----------------------------------------------------------------------------
74
//-----------------------------------------------------------------------------
76
void MMF::AudioPlayer::doPlay()
81
void MMF::AudioPlayer::doPause()
86
void MMF::AudioPlayer::doStop()
91
void MMF::AudioPlayer::doSeek(qint64 ms)
93
m_player->SetPosition(TTimeIntervalMicroSeconds(ms * 1000));
96
int MMF::AudioPlayer::setDeviceVolume(int mmfVolume)
98
/* In SDK 3.1, SetVolume() returns void. If we're compiling against
99
* 3.1, we handle it with ifdefs. However, if we compile against a later
100
* SDK but are _running_ against 3.1, we avoid returning from an undefined
101
* stack by doing a runtime check of the SDK version. */
102
#if !defined(__SERIES60_31__)
103
const int err = m_player->SetVolume(mmfVolume);
104
if (QSysInfo::s60Version() >= QSysInfo::SV_S60_5_0)
109
m_player->SetVolume(mmfVolume);
114
int MMF::AudioPlayer::openFile(RFile& file)
116
TRAPD(err, m_player->OpenFileL(file));
118
#ifdef QT_PHONON_MMF_AUDIO_DRM
119
if (KErrNone == err) {
120
// There appears to be a bug in the CDrmPlayerUtility implementation (at least
121
// in S60 5.x) whereby the player does not check whether the loading observer
122
// pointer is null before dereferencing it. Therefore we must register for
123
// loading notification, even though we do nothing in the callback functions.
124
m_player->RegisterForAudioLoadingNotification(*this);
131
void MMF::AudioPlayer::close()
136
bool MMF::AudioPlayer::hasVideo() const
141
qint64 MMF::AudioPlayer::currentTime() const
143
TRACE_CONTEXT(AudioPlayer::currentTime, EAudioApi);
145
TTimeIntervalMicroSeconds us;
146
const TInt err = m_player->GetPosition(us);
150
if (KErrNone == err) {
151
result = toMilliSeconds(us);
153
TRACE("GetPosition err %d", err);
155
// If we don't cast away constness here, we simply have to ignore
157
const_cast<AudioPlayer*>(this)->setError(NormalError);
163
qint64 MMF::AudioPlayer::totalTime() const
165
return toMilliSeconds(m_player->Duration());
169
//-----------------------------------------------------------------------------
170
// Symbian multimedia client observer callbacks
171
//-----------------------------------------------------------------------------
173
#ifdef QT_PHONON_MMF_AUDIO_DRM
174
void MMF::AudioPlayer::MdapcInitComplete(TInt aError,
175
const TTimeIntervalMicroSeconds &)
177
void MMF::AudioPlayer::MapcInitComplete(TInt aError,
178
const TTimeIntervalMicroSeconds &)
181
TRACE_CONTEXT(AudioPlayer::MapcInitComplete, EAudioInternal);
182
TRACE_ENTRY("state %d error %d", state(), aError);
184
__ASSERT_ALWAYS(LoadingState == state(), Utils::panic(InvalidStatePanic));
186
if (KErrNone == aError) {
187
maxVolumeChanged(m_player->MaxVolume());
189
emit totalTimeChanged(totalTime());
190
changeState(StoppedState);
192
// TODO: set different error states according to value of aError?
193
setError(NormalError);
199
#ifdef QT_PHONON_MMF_AUDIO_DRM
200
void MMF::AudioPlayer::MdapcPlayComplete(TInt aError)
202
void MMF::AudioPlayer::MapcPlayComplete(TInt aError)
205
TRACE_CONTEXT(AudioPlayer::MapcPlayComplete, EAudioInternal);
206
TRACE_ENTRY("state %d error %d", state(), aError);
210
if (KErrNone == aError) {
211
changeState(StoppedState);
212
// TODO: move on to m_nextSource
214
// TODO: do something with aError?
215
setError(NormalError);
219
if(aError == KErrNone) {
220
if(m_nextSource.type() == MediaSource::Empty) {
223
setSource(m_nextSource);
224
m_nextSource = MediaSource();
227
changeState(StoppedState);
230
m_error = NormalError;
231
changeState(ErrorState);
238
CPlayerType *MMF::AudioPlayer::player() const
244
#ifdef QT_PHONON_MMF_AUDIO_DRM
245
void MMF::AudioPlayer::MaloLoadingStarted()
250
void MMF::AudioPlayer::MaloLoadingComplete()
254
#endif // QT_PHONON_MMF_AUDIO_DRM