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

almost work with libvlc with some small issues

not yet any error management

restoredoes notwork when playing a track, restored position and volume
will be 0
parent 40bf3cec
This diff is collapsed.
......@@ -164,9 +164,9 @@ private Q_SLOTS:
private:
void playerStateSignalChanges();
void playerStateSignalChanges(QMediaPlayer::State newState);
void mediaStatusSignalChanges();
void mediaStatusSignalChanges(QMediaPlayer::MediaStatus newStatus);
void playerPositionSignalChanges(qint64 newPosition);
......
......@@ -194,12 +194,13 @@ void AudioWrapper::setSource(const QUrl &source)
d->mPlayer = libvlc_media_player_new_from_media(d->mMedia);
d->signalMediaStatusChange(QMediaPlayer::LoadingMedia);
if (d->signalPlaybackChange(QMediaPlayer::StoppedState)) {
Q_EMIT stopped();
}
d->signalMediaStatusChange(QMediaPlayer::LoadingMedia);
d->signalMediaStatusChange(QMediaPlayer::LoadedMedia);
d->signalMediaStatusChange(QMediaPlayer::BufferingMedia);
d->signalMediaStatusChange(QMediaPlayer::BufferedMedia);
d->mStateRefreshTimer.start();
}
......@@ -214,8 +215,6 @@ void AudioWrapper::setPosition(qint64 position)
return;
}
qDebug() << "AudioWrapper::setPosition" << position << (static_cast<float>(position) / d->mMediaDuration);
libvlc_media_player_set_position(d->mPlayer, static_cast<float>(position) / d->mMediaDuration);
}
......@@ -225,8 +224,6 @@ void AudioWrapper::play()
return;
}
qDebug() << "AudioWrapper::play";
libvlc_media_player_play(d->mPlayer);
}
......@@ -236,8 +233,6 @@ void AudioWrapper::pause()
return;
}
qDebug() << "AudioWrapper::pause";
libvlc_media_player_pause(d->mPlayer);
}
......@@ -247,8 +242,6 @@ void AudioWrapper::stop()
return;
}
qDebug() << "AudioWrapper::stop";
libvlc_media_player_stop(d->mPlayer);
}
......@@ -289,7 +282,7 @@ void AudioWrapper::playerStateChanged()
d->signalMediaStatusChange(QMediaPlayer::LoadedMedia);
break;
case libvlc_Buffering:
d->signalMediaStatusChange(QMediaPlayer::BufferingMedia);
d->signalMediaStatusChange(QMediaPlayer::BufferedMedia);
break;
case libvlc_NothingSpecial:
break;
......@@ -342,14 +335,14 @@ void AudioWrapper::playerVolumeChanged()
{
}
void AudioWrapper::playerStateSignalChanges()
void AudioWrapper::playerStateSignalChanges(QMediaPlayer::State newState)
{
QTimer::singleShot(0, [this]() {Q_EMIT playbackStateChanged(d->mPreviousPlayerState);});
QTimer::singleShot(0, [this, newState]() {Q_EMIT playbackStateChanged(newState);});
}
void AudioWrapper::mediaStatusSignalChanges()
void AudioWrapper::mediaStatusSignalChanges(QMediaPlayer::MediaStatus newStatus)
{
QTimer::singleShot(0, [this]() {Q_EMIT statusChanged(d->mPreviousMediaStatus);});
QTimer::singleShot(0, [this, newStatus]() {Q_EMIT statusChanged(newStatus);});
}
void AudioWrapper::playerPositionSignalChanges(qint64 newPosition)
......@@ -369,8 +362,6 @@ void AudioWrapper::playerMutedSignalChanges()
void AudioWrapperPrivate::mediaIsEnded()
{
qDebug() << "AudioWrapper::mediaIsEnded";
libvlc_media_release(mMedia);
mMedia = nullptr;
......@@ -386,8 +377,7 @@ bool AudioWrapperPrivate::signalPlaybackChange(QMediaPlayer::State newPlayerStat
if (mPreviousPlayerState != newPlayerState) {
mPreviousPlayerState = newPlayerState;
qDebug() << "playbackStateChanged" << mPreviousPlayerState;
mParent->playerStateChanged();
mParent->playerStateSignalChanges(mPreviousPlayerState);
return true;
}
......@@ -400,8 +390,7 @@ void AudioWrapperPrivate::signalMediaStatusChange(QMediaPlayer::MediaStatus newM
if (mPreviousMediaStatus != newMediaStatus) {
mPreviousMediaStatus = newMediaStatus;
qDebug() << "statusChanged" << mPreviousMediaStatus;
mParent->mediaStatusSignalChanges();
mParent->mediaStatusSignalChanges(mPreviousMediaStatus);
}
}
......@@ -418,7 +407,6 @@ void AudioWrapperPrivate::signalVolumeChange(int newVolume)
if (abs(mPreviousVolume - newVolume) > 0.01) {
mPreviousVolume = newVolume;
qDebug() << "volumeChanged" << mPreviousVolume;
mParent->playerVolumeSignalChanges();
}
}
......@@ -428,7 +416,6 @@ void AudioWrapperPrivate::signalPositionChange(qint64 newPosition)
if (mPreviousPosition != newPosition) {
mPreviousPosition = newPosition;
qDebug() << "positionChanged" << mPreviousPosition;
mParent->playerPositionSignalChanges(mPreviousPosition);
}
}
......
......@@ -154,12 +154,10 @@ void AudioWrapper::setAudioRole(QAudio::Role audioRole)
void AudioWrapper::mediaStatusChanged()
{
qDebug() << "statusChanged" << d->mPlayer.mediaStatus();
}
void AudioWrapper::playerStateChanged()
{
qDebug() << "playbackStateChanged" << d->mPlayer.state();
switch(d->mPlayer.state())
{
case QMediaPlayer::State::StoppedState:
......
......@@ -409,10 +409,8 @@ void ElisaApplication::initializePlayer()
QObject::connect(d->mMediaPlayList.get(), &MediaPlayList::playListFinished, d->mAudioControl.get(), &ManageAudioPlayer::playListFinished);
QObject::connect(d->mMediaPlayList.get(), &MediaPlayList::currentTrackChanged, d->mAudioControl.get(), &ManageAudioPlayer::setCurrentTrack);
QObject::connect(d->mAudioWrapper.get(), &AudioWrapper::playbackStateChanged, d->mAudioControl.get(),
[this](QMediaPlayer::State state) {
d->mAudioControl->setPlayerPlaybackState(static_cast<int>(state));
});
QObject::connect(d->mAudioWrapper.get(), &AudioWrapper::playbackStateChanged,
d->mAudioControl.get(), &ManageAudioPlayer::setPlayerPlaybackState);
QObject::connect(d->mAudioWrapper.get(), &AudioWrapper::statusChanged, d->mAudioControl.get(), &ManageAudioPlayer::setPlayerStatus);
QObject::connect(d->mAudioWrapper.get(), &AudioWrapper::errorChanged, d->mAudioControl.get(), &ManageAudioPlayer::setPlayerError);
QObject::connect(d->mAudioWrapper.get(), &AudioWrapper::durationChanged, d->mAudioControl.get(), &ManageAudioPlayer::setAudioDuration);
......
......@@ -60,7 +60,7 @@ QMediaPlayer::MediaStatus ManageAudioPlayer::playerStatus() const
return mPlayerStatus;
}
int ManageAudioPlayer::playerPlaybackState() const
QMediaPlayer::State ManageAudioPlayer::playerPlaybackState() const
{
return mPlayerPlaybackState;
}
......@@ -151,11 +151,11 @@ void ManageAudioPlayer::setCurrentTrack(const QPersistentModelIndex &currentTrac
}
switch (mPlayerPlaybackState) {
case StoppedState:
case QMediaPlayer::StoppedState:
notifyPlayerSourceProperty();
break;
case PlayingState:
case PausedState:
case QMediaPlayer::PlayingState:
case QMediaPlayer::PausedState:
triggerStop();
if (mPlayingState && !mCurrentTrack.isValid()) {
mPlayingState = false;
......@@ -208,11 +208,7 @@ void ManageAudioPlayer::setPlayerStatus(QMediaPlayer::MediaStatus playerStatus)
return;
}
if (playerStatus < static_cast<int>(QMediaPlayer::UnknownMediaStatus) || playerStatus > static_cast<int>(QMediaPlayer::InvalidMedia)) {
return;
}
mPlayerStatus = static_cast<QMediaPlayer::MediaStatus>(playerStatus);
mPlayerStatus = playerStatus;
Q_EMIT playerStatusChanged();
switch (mPlayerStatus) {
......@@ -241,22 +237,18 @@ void ManageAudioPlayer::setPlayerStatus(QMediaPlayer::MediaStatus playerStatus)
}
}
void ManageAudioPlayer::setPlayerPlaybackState(int playerPlaybackState)
void ManageAudioPlayer::setPlayerPlaybackState(QMediaPlayer::State playerPlaybackState)
{
if (mPlayerPlaybackState == playerPlaybackState) {
return;
}
if (playerPlaybackState < static_cast<int>(StoppedState) || playerPlaybackState > static_cast<int>(PausedState)) {
return;
}
mPlayerPlaybackState = static_cast<PlayerPlaybackState>(playerPlaybackState);
mPlayerPlaybackState = playerPlaybackState;
Q_EMIT playerPlaybackStateChanged();
if (!mSkippingCurrentTrack) {
switch(mPlayerPlaybackState) {
case StoppedState:
case QMediaPlayer::StoppedState:
if (mPlayerStatus == QMediaPlayer::EndOfMedia || mPlayerStatus == QMediaPlayer::InvalidMedia) {
triggerSkipNextTrack();
}
......@@ -264,12 +256,12 @@ void ManageAudioPlayer::setPlayerPlaybackState(int playerPlaybackState)
mPlayListModel->setData(mCurrentTrack, MediaPlayList::NotPlaying, mIsPlayingRole);
}
break;
case PlayingState:
case QMediaPlayer::PlayingState:
if (mPlayListModel && mCurrentTrack.isValid()) {
mPlayListModel->setData(mCurrentTrack, MediaPlayList::IsPlaying, mIsPlayingRole);
}
break;
case PausedState:
case QMediaPlayer::PausedState:
if (mPlayListModel && mCurrentTrack.isValid()) {
mPlayListModel->setData(mCurrentTrack, MediaPlayList::IsPaused, mIsPlayingRole);
}
......@@ -277,19 +269,19 @@ void ManageAudioPlayer::setPlayerPlaybackState(int playerPlaybackState)
}
} else {
switch(mPlayerPlaybackState) {
case StoppedState:
case QMediaPlayer::StoppedState:
notifyPlayerSourceProperty();
mSkippingCurrentTrack = false;
if (mPlayListModel && mOldCurrentTrack.isValid()) {
mPlayListModel->setData(mOldCurrentTrack, MediaPlayList::NotPlaying, mIsPlayingRole);
}
break;
case PlayingState:
case QMediaPlayer::PlayingState:
if (mPlayListModel && mCurrentTrack.isValid()) {
mPlayListModel->setData(mCurrentTrack, MediaPlayList::IsPlaying, mIsPlayingRole);
}
break;
case PausedState:
case QMediaPlayer::PausedState:
if (mPlayListModel && mCurrentTrack.isValid()) {
mPlayListModel->setData(mCurrentTrack, MediaPlayList::IsPaused, mIsPlayingRole);
}
......@@ -358,9 +350,9 @@ void ManageAudioPlayer::playPause()
}
break;
case QMediaPlayer::EndOfMedia:
if (mPlayerPlaybackState == PlayingState && !mPlayingState) {
if (mPlayerPlaybackState == QMediaPlayer::PlayingState && !mPlayingState) {
triggerPause();
} else if (mPlayerPlaybackState == PausedState && mPlayingState) {
} else if (mPlayerPlaybackState == QMediaPlayer::PausedState && mPlayingState) {
triggerPlay();
}
break;
......
......@@ -74,7 +74,7 @@ class ELISALIB_EXPORT ManageAudioPlayer : public QObject
WRITE setPlayerStatus
NOTIFY playerStatusChanged)
Q_PROPERTY(int playerPlaybackState
Q_PROPERTY(QMediaPlayer::State playerPlaybackState
READ playerPlaybackState
WRITE setPlayerPlaybackState
NOTIFY playerPlaybackStateChanged)
......@@ -111,14 +111,6 @@ class ELISALIB_EXPORT ManageAudioPlayer : public QObject
public:
enum PlayerPlaybackState {
PlayingState = 1,
PausedState = 2,
StoppedState = 0,
};
Q_ENUM(PlayerPlaybackState)
explicit ManageAudioPlayer(QObject *parent = nullptr);
QPersistentModelIndex currentTrack() const;
......@@ -133,7 +125,7 @@ public:
QMediaPlayer::MediaStatus playerStatus() const;
int playerPlaybackState() const;
QMediaPlayer::State playerPlaybackState() const;
QMediaPlayer::Error playerError() const;
......@@ -215,7 +207,7 @@ public Q_SLOTS:
void setPlayerStatus(QMediaPlayer::MediaStatus playerStatus);
void setPlayerPlaybackState(int playerPlaybackState);
void setPlayerPlaybackState(QMediaPlayer::State playerPlaybackState);
void setPlayerError(QMediaPlayer::Error playerError);
......@@ -283,7 +275,7 @@ private:
QMediaPlayer::MediaStatus mPlayerStatus = QMediaPlayer::NoMedia;
PlayerPlaybackState mPlayerPlaybackState = StoppedState;
QMediaPlayer::State mPlayerPlaybackState = QMediaPlayer::StoppedState;
QMediaPlayer::Error mPlayerError = QMediaPlayer::NoError;
......
......@@ -86,9 +86,9 @@ QString MediaPlayer2Player::PlaybackStatus() const
return result;
}
if (m_manageAudioPlayer->playerPlaybackState() == ManageAudioPlayer::StoppedState) {
if (m_manageAudioPlayer->playerPlaybackState() == QMediaPlayer::StoppedState) {
result = QStringLiteral("Stopped");
} else if (m_manageAudioPlayer->playerPlaybackState() == ManageAudioPlayer::PlayingState) {
} else if (m_manageAudioPlayer->playerPlaybackState() == QMediaPlayer::PlayingState) {
result = QStringLiteral("Playing");
} else {
result = QStringLiteral("Paused");
......
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