AVFoundation: implemented QMediaPlayer::seekable.

Change-Id: Iaca8daa2460062954497b3e510dd1828953c80fd
Reviewed-by: Christian Stromme <christian.stromme@theqtcompany.com>
This commit is contained in:
Yoann Lopes
2015-09-04 18:04:51 +02:00
parent e9cf6670fe
commit 9c5292927e
3 changed files with 19 additions and 1 deletions

View File

@@ -65,6 +65,8 @@ void AVFMediaPlayerControl::setSession(AVFMediaPlayerSession *session)
connect(m_session, SIGNAL(error(int,QString)), this, SIGNAL(error(int,QString))); connect(m_session, SIGNAL(error(int,QString)), this, SIGNAL(error(int,QString)));
connect(m_session, &AVFMediaPlayerSession::playbackRateChanged, connect(m_session, &AVFMediaPlayerSession::playbackRateChanged,
this, &AVFMediaPlayerControl::playbackRateChanged); this, &AVFMediaPlayerControl::playbackRateChanged);
connect(m_session, &AVFMediaPlayerSession::seekableChanged,
this, &AVFMediaPlayerControl::seekableChanged);
} }
QMediaPlayer::State AVFMediaPlayerControl::state() const QMediaPlayer::State AVFMediaPlayerControl::state() const

View File

@@ -109,6 +109,7 @@ Q_SIGNALS:
void audioAvailableChanged(bool audioAvailable); void audioAvailableChanged(bool audioAvailable);
void videoAvailableChanged(bool videoAvailable); void videoAvailableChanged(bool videoAvailable);
void playbackRateChanged(qreal rate); void playbackRateChanged(qreal rate);
void seekableChanged(bool seekable);
void error(int error, const QString &errorString); void error(int error, const QString &errorString);
private: private:
@@ -151,6 +152,7 @@ private:
void setAudioAvailable(bool available); void setAudioAvailable(bool available);
void setVideoAvailable(bool available); void setVideoAvailable(bool available);
void setSeekable(bool seekable);
AVFMediaPlayerService *m_service; AVFMediaPlayerService *m_service;
AVFVideoOutput *m_videoOutput; AVFVideoOutput *m_videoOutput;
@@ -171,6 +173,7 @@ private:
qint64 m_duration; qint64 m_duration;
bool m_videoAvailable; bool m_videoAvailable;
bool m_audioAvailable; bool m_audioAvailable;
bool m_seekable;
void *m_observer; void *m_observer;
}; };

View File

@@ -377,6 +377,7 @@ AVFMediaPlayerSession::AVFMediaPlayerSession(AVFMediaPlayerService *service, QOb
, m_duration(0) , m_duration(0)
, m_videoAvailable(false) , m_videoAvailable(false)
, m_audioAvailable(false) , m_audioAvailable(false)
, m_seekable(false)
{ {
m_observer = [[AVFMediaPlayerSessionObserver alloc] initWithMediaPlayerSession:this]; m_observer = [[AVFMediaPlayerSessionObserver alloc] initWithMediaPlayerSession:this];
} }
@@ -453,6 +454,7 @@ void AVFMediaPlayerSession::setMedia(const QMediaContent &content, QIODevice *st
setAudioAvailable(false); setAudioAvailable(false);
setVideoAvailable(false); setVideoAvailable(false);
setSeekable(false);
m_requestedPosition = -1; m_requestedPosition = -1;
Q_EMIT positionChanged(position()); Q_EMIT positionChanged(position());
@@ -554,7 +556,16 @@ bool AVFMediaPlayerSession::isVideoAvailable() const
bool AVFMediaPlayerSession::isSeekable() const bool AVFMediaPlayerSession::isSeekable() const
{ {
return true; return m_seekable;
}
void AVFMediaPlayerSession::setSeekable(bool seekable)
{
if (m_seekable == seekable)
return;
m_seekable = seekable;
Q_EMIT seekableChanged(seekable);
} }
QMediaTimeRange AVFMediaPlayerSession::availablePlaybackRanges() const QMediaTimeRange AVFMediaPlayerSession::availablePlaybackRanges() const
@@ -806,6 +817,8 @@ void AVFMediaPlayerSession::processLoadStateChange()
} }
} }
setSeekable([[playerItem seekableTimeRanges] count] > 0);
// Get the native size of the video, and reset the bounds of the player layer // Get the native size of the video, and reset the bounds of the player layer
AVPlayerLayer *playerLayer = [(AVFMediaPlayerSessionObserver*)m_observer playerLayer]; AVPlayerLayer *playerLayer = [(AVFMediaPlayerSessionObserver*)m_observer playerLayer];
if (videoTrack && playerLayer) { if (videoTrack && playerLayer) {