43 // Constructor / destructor |
43 // Constructor / destructor |
44 //----------------------------------------------------------------------------- |
44 //----------------------------------------------------------------------------- |
45 |
45 |
46 MMF::MediaObject::MediaObject(QObject *parent) : MMF::MediaNode::MediaNode(parent) |
46 MMF::MediaObject::MediaObject(QObject *parent) : MMF::MediaNode::MediaNode(parent) |
47 , m_recognizerOpened(false) |
47 , m_recognizerOpened(false) |
|
48 , m_nextSourceSet(false) |
48 { |
49 { |
49 m_player.reset(new DummyPlayer()); |
50 m_player.reset(new DummyPlayer()); |
50 |
51 |
51 TRACE_CONTEXT(MediaObject::MediaObject, EAudioApi); |
52 TRACE_CONTEXT(MediaObject::MediaObject, EAudioApi); |
52 TRACE_ENTRY_0(); |
53 TRACE_ENTRY_0(); |
209 return m_player->totalTime(); |
210 return m_player->totalTime(); |
210 } |
211 } |
211 |
212 |
212 MediaSource MMF::MediaObject::source() const |
213 MediaSource MMF::MediaObject::source() const |
213 { |
214 { |
214 return m_player->source(); |
215 return m_source; |
215 } |
216 } |
216 |
217 |
217 void MMF::MediaObject::setSource(const MediaSource &source) |
218 void MMF::MediaObject::setSource(const MediaSource &source) |
218 { |
219 { |
|
220 switchToSource(source); |
|
221 } |
|
222 |
|
223 void MMF::MediaObject::switchToSource(const MediaSource &source) |
|
224 { |
219 createPlayer(source); |
225 createPlayer(source); |
220 |
226 m_source = source; |
221 // This is a hack to work around KErrInUse from MMF client utility |
227 m_player->open(m_source, m_file); |
222 // OpenFileL calls |
228 emit currentSourceChanged(m_source); |
223 m_player->setFileSource(source, m_file); |
|
224 |
|
225 emit currentSourceChanged(source); |
|
226 } |
229 } |
227 |
230 |
228 void MMF::MediaObject::createPlayer(const MediaSource &source) |
231 void MMF::MediaObject::createPlayer(const MediaSource &source) |
229 { |
232 { |
230 TRACE_CONTEXT(MediaObject::createPlayer, EAudioApi); |
233 TRACE_CONTEXT(MediaObject::createPlayer, EAudioApi); |
236 AbstractPlayer* oldPlayer = m_player.data(); |
239 AbstractPlayer* oldPlayer = m_player.data(); |
237 |
240 |
238 const bool oldPlayerHasVideo = oldPlayer->hasVideo(); |
241 const bool oldPlayerHasVideo = oldPlayer->hasVideo(); |
239 const bool oldPlayerSeekable = oldPlayer->isSeekable(); |
242 const bool oldPlayerSeekable = oldPlayer->isSeekable(); |
240 |
243 |
241 Phonon::ErrorType error = NoError; |
|
242 QString errorMessage; |
244 QString errorMessage; |
243 |
245 |
244 // Determine media type |
246 // Determine media type |
245 switch (source.type()) { |
247 switch (source.type()) { |
246 case MediaSource::LocalFile: |
248 case MediaSource::LocalFile: |
252 const QUrl url(source.url()); |
254 const QUrl url(source.url()); |
253 if (url.scheme() == QLatin1String("file")) { |
255 if (url.scheme() == QLatin1String("file")) { |
254 mediaType = fileMediaType(url.toLocalFile()); |
256 mediaType = fileMediaType(url.toLocalFile()); |
255 } |
257 } |
256 else { |
258 else { |
257 errorMessage = QLatin1String("Network streaming not supported yet"); |
259 // Streaming playback is generally not supported by the implementation |
258 error = NormalError; |
260 // of the audio player API, so we use CVideoPlayerUtility for both |
|
261 // audio and video streaming. |
|
262 mediaType = MediaTypeVideo; |
259 } |
263 } |
260 } |
264 } |
261 break; |
265 break; |
262 |
266 |
263 case MediaSource::Invalid: |
267 case MediaSource::Invalid: |
264 case MediaSource::Disc: |
268 case MediaSource::Disc: |
265 case MediaSource::Stream: |
269 case MediaSource::Stream: |
266 TRACE_0("Unsupported media type"); |
270 errorMessage = tr("Error opening source: type not supported"); |
267 error = NormalError; |
|
268 break; |
271 break; |
269 |
272 |
270 case MediaSource::Empty: |
273 case MediaSource::Empty: |
271 TRACE_0("Empty media source"); |
274 TRACE_0("Empty media source"); |
272 break; |
275 break; |
279 // been set on oldPlayer. |
282 // been set on oldPlayer. |
280 |
283 |
281 switch (mediaType) { |
284 switch (mediaType) { |
282 case MediaTypeUnknown: |
285 case MediaTypeUnknown: |
283 TRACE_0("Media type could not be determined"); |
286 TRACE_0("Media type could not be determined"); |
284 if (oldPlayer) { |
287 newPlayer = new DummyPlayer(oldPlayer); |
285 newPlayer = new DummyPlayer(*oldPlayer); |
288 errorMessage = tr("Error opening source: media type could not be determined"); |
286 } else { |
|
287 newPlayer = new DummyPlayer(); |
|
288 } |
|
289 |
|
290 error = NormalError; |
|
291 errorMessage = tr("Media type could not be determined"); |
|
292 break; |
289 break; |
293 |
290 |
294 case MediaTypeAudio: |
291 case MediaTypeAudio: |
295 if (oldPlayer) { |
292 newPlayer = new AudioPlayer(this, oldPlayer); |
296 newPlayer = new AudioPlayer(*oldPlayer); |
|
297 } else { |
|
298 newPlayer = new AudioPlayer(); |
|
299 } |
|
300 break; |
293 break; |
301 |
294 |
302 case MediaTypeVideo: |
295 case MediaTypeVideo: |
303 if (oldPlayer) { |
296 newPlayer = new VideoPlayer(this, oldPlayer); |
304 newPlayer = new VideoPlayer(*oldPlayer); |
297 break; |
305 } else { |
298 } |
306 newPlayer = new VideoPlayer(); |
299 |
307 } |
300 if (oldPlayer) |
308 break; |
301 emit abstractPlayerChanged(0); |
309 } |
|
310 |
|
311 m_player.reset(newPlayer); |
302 m_player.reset(newPlayer); |
|
303 emit abstractPlayerChanged(newPlayer); |
312 |
304 |
313 if (oldPlayerHasVideo != hasVideo()) { |
305 if (oldPlayerHasVideo != hasVideo()) { |
314 emit hasVideoChanged(hasVideo()); |
306 emit hasVideoChanged(hasVideo()); |
315 } |
307 } |
316 |
308 |
320 |
312 |
321 connect(m_player.data(), SIGNAL(totalTimeChanged(qint64)), SIGNAL(totalTimeChanged(qint64))); |
313 connect(m_player.data(), SIGNAL(totalTimeChanged(qint64)), SIGNAL(totalTimeChanged(qint64))); |
322 connect(m_player.data(), SIGNAL(stateChanged(Phonon::State,Phonon::State)), SIGNAL(stateChanged(Phonon::State,Phonon::State))); |
314 connect(m_player.data(), SIGNAL(stateChanged(Phonon::State,Phonon::State)), SIGNAL(stateChanged(Phonon::State,Phonon::State))); |
323 connect(m_player.data(), SIGNAL(finished()), SIGNAL(finished())); |
315 connect(m_player.data(), SIGNAL(finished()), SIGNAL(finished())); |
324 connect(m_player.data(), SIGNAL(tick(qint64)), SIGNAL(tick(qint64))); |
316 connect(m_player.data(), SIGNAL(tick(qint64)), SIGNAL(tick(qint64))); |
|
317 connect(m_player.data(), SIGNAL(bufferStatus(int)), SIGNAL(bufferStatus(int))); |
325 connect(m_player.data(), SIGNAL(metaDataChanged(QMultiMap<QString,QString>)), SIGNAL(metaDataChanged(QMultiMap<QString,QString>))); |
318 connect(m_player.data(), SIGNAL(metaDataChanged(QMultiMap<QString,QString>)), SIGNAL(metaDataChanged(QMultiMap<QString,QString>))); |
|
319 connect(m_player.data(), SIGNAL(aboutToFinish()), SIGNAL(aboutToFinish())); |
|
320 connect(m_player.data(), SIGNAL(prefinishMarkReached(qint32)), SIGNAL(tick(qint32))); |
326 |
321 |
327 // We need to call setError() after doing the connects, otherwise the |
322 // We need to call setError() after doing the connects, otherwise the |
328 // error won't be received. |
323 // error won't be received. |
329 if (error != NoError) { |
324 if (!errorMessage.isEmpty()) { |
330 Q_ASSERT(m_player); |
325 Q_ASSERT(m_player); |
331 m_player->setError(error, errorMessage); |
326 m_player->setError(errorMessage); |
332 } |
327 } |
333 |
328 |
334 TRACE_EXIT_0(); |
329 TRACE_EXIT_0(); |
335 } |
330 } |
336 |
331 |
337 void MMF::MediaObject::setNextSource(const MediaSource &source) |
332 void MMF::MediaObject::setNextSource(const MediaSource &source) |
338 { |
333 { |
339 m_player->setNextSource(source); |
334 m_nextSource = source; |
|
335 m_nextSourceSet = true; |
340 } |
336 } |
341 |
337 |
342 qint32 MMF::MediaObject::prefinishMark() const |
338 qint32 MMF::MediaObject::prefinishMark() const |
343 { |
339 { |
344 return m_player->prefinishMark(); |
340 return m_player->prefinishMark(); |
363 { |
359 { |
364 m_player->volumeChanged(volume); |
360 m_player->volumeChanged(volume); |
365 } |
361 } |
366 |
362 |
367 //----------------------------------------------------------------------------- |
363 //----------------------------------------------------------------------------- |
|
364 // MediaNode |
|
365 //----------------------------------------------------------------------------- |
|
366 |
|
367 void MMF::MediaObject::connectMediaObject(MediaObject * /*mediaObject*/) |
|
368 { |
|
369 // This function should never be called - see MediaNode::setMediaObject() |
|
370 Q_ASSERT_X(false, Q_FUNC_INFO, |
|
371 "Connection of MediaObject to MediaObject"); |
|
372 } |
|
373 |
|
374 void MMF::MediaObject::disconnectMediaObject(MediaObject * /*mediaObject*/) |
|
375 { |
|
376 // This function should never be called - see MediaNode::setMediaObject() |
|
377 Q_ASSERT_X(false, Q_FUNC_INFO, |
|
378 "Disconnection of MediaObject from MediaObject"); |
|
379 } |
|
380 |
|
381 |
|
382 //----------------------------------------------------------------------------- |
368 // Video output |
383 // Video output |
369 //----------------------------------------------------------------------------- |
384 //----------------------------------------------------------------------------- |
370 |
385 |
371 void MMF::MediaObject::setVideoOutput(VideoOutput* videoOutput) |
386 void MMF::MediaObject::setVideoOutput(VideoOutput* videoOutput) |
372 { |
387 { |
377 AbstractPlayer *MMF::MediaObject::abstractPlayer() const |
392 AbstractPlayer *MMF::MediaObject::abstractPlayer() const |
378 { |
393 { |
379 return m_player.data(); |
394 return m_player.data(); |
380 } |
395 } |
381 |
396 |
382 bool MMF::MediaObject::activateOnMediaObject(MediaObject *) |
397 //----------------------------------------------------------------------------- |
383 { |
398 // Playlist support |
384 // Guess what, we do nothing. |
399 //----------------------------------------------------------------------------- |
385 return true; |
400 |
|
401 void MMF::MediaObject::switchToNextSource() |
|
402 { |
|
403 if (m_nextSourceSet) { |
|
404 m_nextSourceSet = false; |
|
405 switchToSource(m_nextSource); |
|
406 play(); |
|
407 } |
386 } |
408 } |
387 |
409 |
388 QT_END_NAMESPACE |
410 QT_END_NAMESPACE |
389 |
411 |