diff options
author | Justin McPherson <justin.mcpherson@nokia.com> | 2010-02-19 07:12:33 (GMT) |
---|---|---|
committer | Justin McPherson <justin.mcpherson@nokia.com> | 2010-02-19 07:12:33 (GMT) |
commit | c7632bc03c2123dcc7d2242d4782a0d8be477cdc (patch) | |
tree | cc8028022e7b4e1566d9b199982f58adbbc17412 /src/plugins/mediaservices/qt7/mediaplayer/qt7playersession.mm | |
parent | f95a3014171361672c3307b8dd080e5369d6e017 (diff) | |
parent | 90b9d45d77b25769834d4b879baff13a3327f4ce (diff) | |
download | Qt-c7632bc03c2123dcc7d2242d4782a0d8be477cdc.zip Qt-c7632bc03c2123dcc7d2242d4782a0d8be477cdc.tar.gz Qt-c7632bc03c2123dcc7d2242d4782a0d8be477cdc.tar.bz2 |
Merge branch 'master' of git@scm.dev.nokia.troll.no:qt/qt-multimedia-team
Diffstat (limited to 'src/plugins/mediaservices/qt7/mediaplayer/qt7playersession.mm')
-rw-r--r-- | src/plugins/mediaservices/qt7/mediaplayer/qt7playersession.mm | 149 |
1 files changed, 121 insertions, 28 deletions
diff --git a/src/plugins/mediaservices/qt7/mediaplayer/qt7playersession.mm b/src/plugins/mediaservices/qt7/mediaplayer/qt7playersession.mm index d9bb646..d1381fe 100644 --- a/src/plugins/mediaservices/qt7/mediaplayer/qt7playersession.mm +++ b/src/plugins/mediaservices/qt7/mediaplayer/qt7playersession.mm @@ -68,6 +68,7 @@ QT_BEGIN_NAMESPACE - (QTMovieObserver *) initWithPlayerSession:(QT7PlayerSession*)session; - (void) setMovie:(QTMovie *)movie; - (void) processEOS:(NSNotification *)notification; +- (void) processStateChange:(NSNotification *)notification; @end @implementation QTMovieObserver @@ -97,6 +98,15 @@ QT_BEGIN_NAMESPACE [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(processEOS:) name: QTMovieDidEndNotification object: m_movie]; + [[NSNotificationCenter defaultCenter] addObserver: self selector: + @selector(processStateChange:) name: QTMovieLoadStateDidChangeNotification object: m_movie]; + + [[NSNotificationCenter defaultCenter] addObserver: self selector: + @selector(processVolumeChange:) name: QTMovieVolumeDidChangeNotification object: m_movie]; + + [[NSNotificationCenter defaultCenter] addObserver: self selector: + @selector(processNaturalSizeChange:) name: QTMovieNaturalSizeDidChangeNotification object: m_movie]; + [movie retain]; } } @@ -107,6 +117,24 @@ QT_BEGIN_NAMESPACE m_session->processEOS(); } +- (void) processStateChange:(NSNotification *)notification +{ + Q_UNUSED(notification); + m_session->processStateChange(); +} + +- (void) processVolumeChange:(NSNotification *)notification +{ + Q_UNUSED(notification); + m_session->processVolumeChange(); +} + +- (void) processNaturalSizeChange :(NSNotification *)notification +{ + Q_UNUSED(notification); + m_session->processNaturalSizeChange(); +} + @end static CFStringRef qString2CFStringRef(const QString &string) @@ -145,8 +173,6 @@ void QT7PlayerSession::setVideoOutput(QT7VideoOutput *output) if (m_videoOutput == output) return; - qDebug() << "set output" << output; - if (m_videoOutput) { m_videoOutput->setEnabled(false); m_videoOutput->setMovie(0); @@ -251,12 +277,11 @@ void QT7PlayerSession::setPosition(qint64 pos) void QT7PlayerSession::play() { - m_state = QMediaPlayer::PlayingState; - float preferredRate = [[(QTMovie*)m_QTMovie attributeForKey:@"QTMoviePreferredRateAttribute"] floatValue]; [(QTMovie*)m_QTMovie setRate:preferredRate*m_rate]; - emit stateChanged(m_state); + if (m_state != QMediaPlayer::PlayingState) + emit stateChanged(m_state = QMediaPlayer::PlayingState); } void QT7PlayerSession::pause() @@ -327,6 +352,7 @@ void QT7PlayerSession::setMedia(const QMediaContent &content, QIODevice *stream) m_resources = content; m_mediaStream = stream; + m_mediaStatus = QMediaPlayer::NoMedia; QUrl url; @@ -335,25 +361,18 @@ void QT7PlayerSession::setMedia(const QMediaContent &content, QIODevice *stream) else return; - NSError *err = 0; - QTDataReference *dataRef = 0; + qDebug() << "Open media" << url; - if ( url.scheme() == "file" ) { - NSString *nsFileName = (NSString *)qString2CFStringRef( url.toLocalFile() ); - dataRef = [QTDataReference dataReferenceWithReferenceToFile:nsFileName]; - } else { - NSString *urlString = (NSString *)qString2CFStringRef( url.toString() ); - NSURL *url = [NSURL URLWithString: urlString]; - dataRef = [QTDataReference dataReferenceWithReferenceToURL:url]; - } + NSError *err = 0; + NSString *urlString = (NSString *)qString2CFStringRef(url.toString()); NSDictionary *attr = [NSDictionary dictionaryWithObjectsAndKeys: - dataRef, QTMovieDataReferenceAttribute, - [NSNumber numberWithBool:YES], QTMovieOpenAsyncOKAttribute, - [NSNumber numberWithBool:YES], QTMovieIsActiveAttribute, - [NSNumber numberWithBool:YES], QTMovieResolveDataRefsAttribute, - [NSNumber numberWithBool:YES], QTMovieDontInteractWithUserAttribute, - nil]; + [NSURL URLWithString:urlString], QTMovieURLAttribute, + [NSNumber numberWithBool:YES], QTMovieOpenAsyncOKAttribute, + [NSNumber numberWithBool:YES], QTMovieIsActiveAttribute, + [NSNumber numberWithBool:YES], QTMovieResolveDataRefsAttribute, + [NSNumber numberWithBool:YES], QTMovieDontInteractWithUserAttribute, + nil]; m_QTMovie = [[QTMovie movieWithAttributes:attr error:&err] retain]; @@ -362,19 +381,15 @@ void QT7PlayerSession::setMedia(const QMediaContent &content, QIODevice *stream) m_QTMovie = 0; QString description = QString::fromUtf8([[err localizedDescription] UTF8String]); - qDebug() << "QT7PlayerSession::setMedia error" << description; emit error(QMediaPlayer::FormatError, description ); } else { [(QTMovieObserver*)m_movieObserver setMovie:(QTMovie*)m_QTMovie]; - if (m_videoOutput) { - m_videoOutput->setEnabled(true); + if (m_videoOutput) { m_videoOutput->setMovie(m_QTMovie); + m_videoOutput->setEnabled(true); } - - emit durationChanged(duration()); - emit audioAvailableChanged(isAudioAvailable()); - emit videoAvailableChanged(isVideoAvailable()); + processStateChange(); [(QTMovie*)m_QTMovie setMuted:m_muted]; setVolume(m_volume); @@ -406,6 +421,84 @@ void QT7PlayerSession::processEOS() emit mediaStatusChanged(m_mediaStatus); } +void QT7PlayerSession::processStateChange() +{ + signed long state = [[(QTMovie*)m_QTMovie attributeForKey:QTMovieLoadStateAttribute] + longValue]; + qDebug() << "Moview load state changed:" << state; + +#ifndef QUICKTIME_C_API_AVAILABLE + enum { + kMovieLoadStateError = -1L, + kMovieLoadStateLoading = 1000, + kMovieLoadStateLoaded = 2000, + kMovieLoadStatePlayable = 10000, + kMovieLoadStatePlaythroughOK = 20000, + kMovieLoadStateComplete = 100000 + }; +#endif + + QMediaPlayer::MediaStatus newStatus = QMediaPlayer::NoMedia; + bool isPlaying = (m_state != QMediaPlayer::StoppedState); + + if (state >= kMovieLoadStateComplete) { + newStatus = isPlaying ? QMediaPlayer::BufferedMedia : QMediaPlayer::LoadedMedia; + } else if (state >= kMovieLoadStatePlayable) + newStatus = isPlaying ? QMediaPlayer::BufferingMedia : QMediaPlayer::LoadingMedia; + else if (state >= kMovieLoadStateLoading) + newStatus = isPlaying ? QMediaPlayer::StalledMedia : QMediaPlayer::LoadingMedia; + + if (state == kMovieLoadStateError) { + newStatus = QMediaPlayer::InvalidMedia; + emit error(QMediaPlayer::FormatError, tr("Playback failed")); + } + + 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; + } + + emit mediaStatusChanged(m_mediaStatus = newStatus); + } +} + +void QT7PlayerSession::processVolumeChange() +{ + if (!m_QTMovie) + return; + + int newVolume = qRound(100.0f*[((QTMovie*)m_QTMovie) volume]); + + if (newVolume != m_volume) { + emit volumeChanged(m_volume = newVolume); + } +} + +void QT7PlayerSession::processNaturalSizeChange() +{ + if (m_videoOutput) { + NSSize size = [[(QTMovie*)m_QTMovie attributeForKey:@"QTMovieNaturalSizeAttribute"] sizeValue]; + qDebug() << "Native size changed:" << QSize(size.width, size.height); + m_videoOutput->updateNaturalSize(QSize(size.width, size.height)); + } +} + #include "moc_qt7playersession.cpp" QT_END_NAMESPACE |