summaryrefslogtreecommitdiffstats
path: root/src/plugins/mediaservices/qt7/mediaplayer/qt7playersession.mm
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/mediaservices/qt7/mediaplayer/qt7playersession.mm')
-rw-r--r--src/plugins/mediaservices/qt7/mediaplayer/qt7playersession.mm64
1 files changed, 35 insertions, 29 deletions
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()