blob: 605fe24ef64b5cb82b6c2d79def7d642ff26289b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
|
/* This file is part of the KDE project.
Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
This library is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2.1 or 3 of the License.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QUrl>
#include <private/qcore_symbian_p.h>
#include "mediaobject.h"
using namespace Phonon;
using namespace Phonon::MMF;
MMF::MediaObject::MediaObject(QObject *parent) : m_player(0)
, m_error(NoError)
, m_state(StoppedState)
{
Q_UNUSED(parent);
m_player = CDrmPlayerUtility::NewL(*this, 0, EMdaPriorityPreferenceNone);
m_player->RegisterForAudioLoadingNotification(*this);
}
MMF::MediaObject::~MediaObject()
{
delete m_player;
}
void MMF::MediaObject::play()
{
transitTo(PlayingState);
m_player->Play();
}
void MMF::MediaObject::pause()
{
transitTo(PausedState);
m_player->Pause();
}
void MMF::MediaObject::stop()
{
transitTo(StoppedState);
m_player->Stop();
}
void MMF::MediaObject::seek(qint64 milliseconds)
{
m_player->SetPosition(toMicroSeconds(milliseconds));
}
qint32 MMF::MediaObject::tickInterval() const
{
return 0;
}
void MMF::MediaObject::setTickInterval(qint32 interval)
{
Q_UNUSED(interval);
}
bool MMF::MediaObject::hasVideo() const
{
return false;
}
bool MMF::MediaObject::isSeekable() const
{
return false;
}
qint64 MMF::MediaObject::currentTime() const
{
TTimeIntervalMicroSeconds mss;
const TInt retcode = m_player->GetPosition(mss);
if(retcode == KErrNone)
return toMilliSeconds(m_player->Duration());
else {
// TODO Should we enter/emit error state? Tricky
// since we're in a const function.
return -1;
}
}
QString MMF::MediaObject::errorString() const
{
return QString();
}
Phonon::ErrorType MMF::MediaObject::errorType() const
{
return m_error;
}
qint64 MMF::MediaObject::toMilliSeconds(const TTimeIntervalMicroSeconds &in)
{
return in.Int64() / 1000;
}
TTimeIntervalMicroSeconds MMF::MediaObject::toMicroSeconds(qint64 ms)
{
return TTimeIntervalMicroSeconds(TInt64(ms));
}
qint64 MMF::MediaObject::totalTime() const
{
return toMilliSeconds(m_player->Duration());
}
MediaSource MMF::MediaObject::source() const
{
return m_mediaSource;
}
void MMF::MediaObject::setSource(const MediaSource &source)
{
stop();
m_mediaSource = source;
switch(m_mediaSource.type())
{
case MediaSource::LocalFile:
{
const QHBufC filename(source.fileName());
m_player->OpenFileL(*filename);
break;
}
case MediaSource::Url:
{
const QHBufC filename(source.url().toString());
m_player->OpenUrlL(*filename);
break;
}
case MediaSource::Invalid:
/* Fallthrough. */
case MediaSource::Disc:
/* Fallthrough. */
case MediaSource::Stream:
/* Fallthrough. */
case MediaSource::Empty:
{
transitTo(ErrorState);
return;
}
}
transitTo(LoadingState);
}
void MMF::MediaObject::setNextSource(const MediaSource &source)
{
m_nextSource = source;
Q_UNUSED(source);
}
qint32 MMF::MediaObject::prefinishMark() const
{
return 0;
}
void MMF::MediaObject::setPrefinishMark(qint32)
{
}
qint32 MMF::MediaObject::transitionTime() const
{
return 0;
}
void MMF::MediaObject::setTransitionTime(qint32)
{
}
void MMF::MediaObject::MaloLoadingComplete()
{
transitTo(StoppedState);
}
void MMF::MediaObject::MaloLoadingStarted()
{
transitTo(LoadingState);
}
void MMF::MediaObject::MdapcInitComplete(TInt aError,
const TTimeIntervalMicroSeconds &)
{
if(aError == KErrNone) {
m_error = NormalError;
m_state = ErrorState;
}
emit totalTimeChanged();
transitTo(StoppedState);
}
void MMF::MediaObject::MdapcPlayComplete(TInt aError)
{
if(aError == KErrNone) {
if(m_nextSource.type() == MediaSource::Empty) {
emit finished();
} else {
setSource(m_nextSource);
m_nextSource = MediaSource();
}
transitTo(StoppedState);
}
else {
m_error = NormalError;
transitTo(ErrorState);
}
}
void MMF::MediaObject::transitTo(Phonon::State newState)
{
emit stateChanged(m_state, newState);
m_state = newState;
}
Phonon::State MMF::MediaObject::state() const
{
return m_state;
}
|