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