Commit d3dd9ff2 authored by Matthieu Gallien's avatar Matthieu Gallien 🎵
Browse files

in case libvlc event is an error, propagate it correctly

parent eca71db5
......@@ -168,6 +168,8 @@ private:
void mediaStatusSignalChanges(QMediaPlayer::MediaStatus newStatus);
void playerErrorSignalChanges(QMediaPlayer::Error error);
void playerDurationSignalChanges(qint64 newDuration);
void playerPositionSignalChanges(qint64 newPosition);
......
......@@ -49,6 +49,8 @@ public:
qint64 mPreviousPosition = 0;
QMediaPlayer::Error mError = QMediaPlayer::NoError;
bool mIsMuted = false;
bool mIsSeekable = false;
......@@ -71,6 +73,8 @@ public:
void signalSeekableChange(bool isSeekable);
void signalErrorChange(QMediaPlayer::Error errorCode);
};
static void vlc_callback(const struct libvlc_event_t *p_event, void *p_data)
......@@ -141,17 +145,7 @@ QUrl AudioWrapper::source() const
QMediaPlayer::Error AudioWrapper::error() const
{
if (!d->mPlayer) {
return {};
}
#if 0
if (d->mPlayer.error() != QMediaPlayer::NoError) {
qDebug() << "AudioWrapper::error" << d->mPlayer.errorString();
}
#endif
return {}/*d->mPlayer.error()*/;
return d->mError;
}
qint64 AudioWrapper::duration() const
......@@ -323,6 +317,11 @@ void AudioWrapper::mediaStatusSignalChanges(QMediaPlayer::MediaStatus newStatus)
QMetaObject::invokeMethod(this, [this, newStatus]() {Q_EMIT statusChanged(newStatus);}, Qt::QueuedConnection);
}
void AudioWrapper::playerErrorSignalChanges(QMediaPlayer::Error error)
{
QMetaObject::invokeMethod(this, [this, error]() {Q_EMIT errorChanged(error);}, Qt::QueuedConnection);
}
void AudioWrapper::playerDurationSignalChanges(qint64 newDuration)
{
QMetaObject::invokeMethod(this, [this, newDuration]() {Q_EMIT durationChanged(newDuration);}, Qt::QueuedConnection);
......@@ -383,6 +382,9 @@ void AudioWrapperPrivate::vlcEventCallback(const struct libvlc_event_t *p_event)
break;
case libvlc_MediaPlayerEncounteredError:
qDebug() << "AudioWrapperPrivate::vlcEventCallback" << "libvlc_MediaPlayerEncounteredError";
signalErrorChange(QMediaPlayer::ResourceError);
mediaIsEnded();
signalMediaStatusChange(QMediaPlayer::InvalidMedia);
break;
case libvlc_MediaPlayerPositionChanged:
//qDebug() << "AudioWrapperPrivate::vlcEventCallback" << "libvlc_MediaPlayerPositionChanged";
......@@ -504,5 +506,14 @@ void AudioWrapperPrivate::signalSeekableChange(bool isSeekable)
}
}
void AudioWrapperPrivate::signalErrorChange(QMediaPlayer::Error errorCode)
{
if (mError != errorCode) {
mError = errorCode;
mParent->playerErrorSignalChanges(errorCode);
}
}
#include "moc_audiowrapper.cpp"
......@@ -179,7 +179,7 @@ void AudioWrapper::playerVolumeChanged()
void AudioWrapper::playerMutedChanged()
{
QTimer::singleShot(0, [this]() {Q_EMIT mutedChanged();});
QTimer::singleShot(0, [this]() {Q_EMIT mutedChanged(muted());});
}
void AudioWrapper::playerStateSignalChanges(QMediaPlayer::State newState)
......@@ -207,9 +207,9 @@ void AudioWrapper::playerVolumeSignalChanges()
QMetaObject::invokeMethod(this, [this]() {Q_EMIT volumeChanged();}, Qt::QueuedConnection);
}
void AudioWrapper::playerMutedSignalChanges()
void AudioWrapper::playerMutedSignalChanges(bool isMuted)
{
QMetaObject::invokeMethod(this, [this]() {Q_EMIT mutedChanged();}, Qt::QueuedConnection);
QMetaObject::invokeMethod(this, [this, isMuted]() {Q_EMIT mutedChanged(isMuted);}, Qt::QueuedConnection);
}
void AudioWrapper::playerSeekableSignalChanges(bool isSeekable)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment