diff options
author | Dmytro Poplavskiy <dmytro.poplavskiy@nokia.com> | 2010-02-25 02:52:29 (GMT) |
---|---|---|
committer | Dmytro Poplavskiy <dmytro.poplavskiy@nokia.com> | 2010-02-25 02:52:29 (GMT) |
commit | 190ec169dd6f5455115e5164cfbacdad214de00a (patch) | |
tree | 0b0b16875980c15377d1625554e1067354cc800c /src | |
parent | e9f3edcb0a0223b90606108993999ad3cb37af9f (diff) | |
download | Qt-190ec169dd6f5455115e5164cfbacdad214de00a.zip Qt-190ec169dd6f5455115e5164cfbacdad214de00a.tar.gz Qt-190ec169dd6f5455115e5164cfbacdad214de00a.tar.bz2 |
Try to start media playback on all load state changes.
QuickTime doesn't start movie playback as soon as it loaded,
it's necessary to start manualy after suitable load state reached.
Reviewed-by: Justin McPherson
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/mediaservices/qt7/mediaplayer/qt7playersession.h | 6 | ||||
-rw-r--r-- | src/plugins/mediaservices/qt7/mediaplayer/qt7playersession.mm | 64 |
2 files changed, 40 insertions, 30 deletions
diff --git a/src/plugins/mediaservices/qt7/mediaplayer/qt7playersession.h b/src/plugins/mediaservices/qt7/mediaplayer/qt7playersession.h index 4742e2e..0ba3041 100644 --- a/src/plugins/mediaservices/qt7/mediaplayer/qt7playersession.h +++ b/src/plugins/mediaservices/qt7/mediaplayer/qt7playersession.h @@ -107,7 +107,7 @@ public slots: void setMuted(bool muted); void processEOS(); - void processStateChange(); + void processLoadStateChange(); void processVolumeChange(); void processNaturalSizeChange(); @@ -138,6 +138,10 @@ private: bool m_muted; int m_volume; qreal m_rate; + + qint64 m_duration; + bool m_videoAvailable; + bool m_audioAvailable; }; QT_END_NAMESPACE diff --git a/src/plugins/mediaservices/qt7/mediaplayer/qt7playersession.mm b/src/plugins/mediaservices/qt7/mediaplayer/qt7playersession.mm index 28e220c..2dd3fe8 100644 --- a/src/plugins/mediaservices/qt7/mediaplayer/qt7playersession.mm +++ b/src/plugins/mediaservices/qt7/mediaplayer/qt7playersession.mm @@ -68,7 +68,9 @@ - (QTMovieObserver *) initWithPlayerSession:(QT7PlayerSession*)session; - (void) setMovie:(QTMovie *)movie; - (void) processEOS:(NSNotification *)notification; -- (void) processStateChange:(NSNotification *)notification; +- (void) processLoadStateChange:(NSNotification *)notification; +- (void) processVolumeChange:(NSNotification *)notification; +- (void) processNaturalSizeChange :(NSNotification *)notification; @end @implementation QTMovieObserver @@ -101,7 +103,7 @@ object:m_movie]; [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(processStateChange:) + selector:@selector(processLoadStateChange:) name:QTMovieLoadStateDidChangeNotification object:m_movie]; @@ -129,10 +131,10 @@ m_session->processEOS(); } -- (void) processStateChange:(NSNotification *)notification +- (void) processLoadStateChange:(NSNotification *)notification { Q_UNUSED(notification); - m_session->processStateChange(); + m_session->processLoadStateChange(); } - (void) processVolumeChange:(NSNotification *)notification @@ -167,6 +169,9 @@ QT7PlayerSession::QT7PlayerSession(QObject *parent) , m_muted(false) , m_volume(100) , m_rate(1.0) + , m_duration(0) + , m_videoAvailable(false) + , m_audioAvailable(false) { m_movieObserver = [[QTMovieObserver alloc] initWithPlayerSession:this]; } @@ -174,7 +179,7 @@ QT7PlayerSession::QT7PlayerSession(QObject *parent) QT7PlayerSession::~QT7PlayerSession() { [(QTMovieObserver*)m_movieObserver setMovie:nil]; - [(QTMovieObserver*)m_movieObserver release]; + [(QTMovieObserver*)m_movieObserver release]; } void *QT7PlayerSession::movie() const @@ -423,7 +428,7 @@ void QT7PlayerSession::setMedia(const QMediaContent &content, QIODevice *stream) m_videoOutput->setMovie(m_QTMovie); m_videoOutput->setEnabled(true); } - processStateChange(); + processLoadStateChange(); [(QTMovie*)m_QTMovie setMuted:m_muted]; setVolume(m_volume); @@ -455,8 +460,11 @@ void QT7PlayerSession::processEOS() emit mediaStatusChanged(m_mediaStatus); } -void QT7PlayerSession::processStateChange() +void QT7PlayerSession::processLoadStateChange() { + if (!m_QTMovie) + return; + signed long state = [[(QTMovie*)m_QTMovie attributeForKey:QTMovieLoadStateAttribute] longValue]; // qDebug() << "Moview load state changed:" << state; @@ -484,32 +492,30 @@ void QT7PlayerSession::processStateChange() if (state == kMovieLoadStateError) { newStatus = QMediaPlayer::InvalidMedia; - emit error(QMediaPlayer::FormatError, tr("Playback failed")); + emit error(QMediaPlayer::FormatError, tr("Failed to load media")); + emit stateChanged(m_state = QMediaPlayer::StoppedState); } - if (newStatus != m_mediaStatus) { - switch (newStatus) { - case QMediaPlayer::BufferedMedia: - case QMediaPlayer::BufferingMedia: - //delayed playback start is necessary for network sources - if (m_state == QMediaPlayer::PlayingState) { - QMetaObject::invokeMethod(this, "play", Qt::QueuedConnection); - } - //fall - case QMediaPlayer::LoadedMedia: - case QMediaPlayer::LoadingMedia: - emit durationChanged(duration()); - emit audioAvailableChanged(isAudioAvailable()); - emit videoAvailableChanged(isVideoAvailable()); - break; - case QMediaPlayer::InvalidMedia: - emit stateChanged(m_state = QMediaPlayer::StoppedState); - default: - break; - } + if (state >= kMovieLoadStatePlayable && + m_state == QMediaPlayer::PlayingState && + [(QTMovie*)m_QTMovie rate] == 0) { + QMetaObject::invokeMethod(this, "play", Qt::QueuedConnection); + } - emit mediaStatusChanged(m_mediaStatus = newStatus); + if (state >= kMovieLoadStateLoaded) { + qint64 currentDuration = duration(); + if (m_duration != currentDuration) + emit durationChanged(m_duration = currentDuration); + + if (m_audioAvailable != isAudioAvailable()) + emit audioAvailableChanged(m_audioAvailable = !m_audioAvailable); + + if (m_videoAvailable != isVideoAvailable()) + emit videoAvailableChanged(m_videoAvailable = !m_videoAvailable); } + + if (newStatus != m_mediaStatus) + emit mediaStatusChanged(m_mediaStatus = newStatus); } void QT7PlayerSession::processVolumeChange() |