Commit 3f5ce3a3 authored by Matthieu Gallien's avatar Matthieu Gallien 🎵
Browse files

fix bug in ManageAudioPlayer related to wrong player state management

parent 59db5b7b
......@@ -82,7 +82,7 @@ endif()
add_executable(playListControlerTest ${playListControlerTest_SOURCES})
target_link_libraries(playListControlerTest Qt5::Test Qt5::Core Qt5::Sql Qt5::Widgets KF5::I18n Qt5::Quick)
target_link_libraries(playListControlerTest Qt5::Test Qt5::Core Qt5::Sql Qt5::Widgets KF5::I18n Qt5::Quick Qt5::Multimedia)
if (KF5Baloo_FOUND)
target_link_libraries(playListControlerTest KF5::Baloo Qt5::DBus)
endif()
......@@ -170,7 +170,7 @@ endif()
add_executable(managemediaplayercontrolTest ${managemediaplayercontrolTest_SOURCES})
target_link_libraries(managemediaplayercontrolTest Qt5::Test Qt5::Core Qt5::Sql Qt5::Widgets KF5::I18n Qt5::Quick)
target_link_libraries(managemediaplayercontrolTest Qt5::Test Qt5::Core Qt5::Sql Qt5::Widgets KF5::I18n Qt5::Quick Qt5::Multimedia)
if (KF5Baloo_FOUND)
target_link_libraries(managemediaplayercontrolTest KF5::Baloo Qt5::DBus)
endif()
......@@ -259,7 +259,7 @@ endif()
add_executable(manageheaderbarTest ${manageheaderbarTest_SOURCES})
target_link_libraries(manageheaderbarTest Qt5::Test Qt5::Core Qt5::Sql Qt5::Gui Qt5::Widgets KF5::I18n Qt5::Quick)
target_link_libraries(manageheaderbarTest Qt5::Test Qt5::Core Qt5::Sql Qt5::Gui Qt5::Widgets KF5::I18n Qt5::Quick Qt5::Multimedia)
if (KF5Baloo_FOUND)
target_link_libraries(manageheaderbarTest KF5::Baloo Qt5::DBus)
endif()
......@@ -288,7 +288,7 @@ set(manageaudioplayerTest_SOURCES
)
add_executable(manageaudioplayerTest ${manageaudioplayerTest_SOURCES})
target_link_libraries(manageaudioplayerTest Qt5::Test Qt5::Core Qt5::Gui)
target_link_libraries(manageaudioplayerTest Qt5::Test Qt5::Core Qt5::Gui Qt5::Multimedia)
target_include_directories(manageaudioplayerTest PRIVATE ${CMAKE_SOURCE_DIR}/src)
add_test(manageaudioplayerTest manageaudioplayerTest)
......@@ -356,7 +356,7 @@ endif()
add_executable(mediaplaylistTest ${mediaplaylistTest_SOURCES})
target_link_libraries(mediaplaylistTest Qt5::Test Qt5::Core Qt5::Sql Qt5::Gui Qt5::Widgets KF5::I18n Qt5::Quick)
target_link_libraries(mediaplaylistTest Qt5::Test Qt5::Core Qt5::Sql Qt5::Gui Qt5::Widgets KF5::I18n Qt5::Quick Qt5::Multimedia)
if (KF5Baloo_FOUND)
target_link_libraries(mediaplaylistTest KF5::Baloo Qt5::DBus)
endif()
......
This diff is collapsed.
......@@ -220,6 +220,7 @@ ApplicationWindow {
onPlayerStop: audioPlayer.stop()
onSkipNextTrack: playListControlerItem.skipNextTrack()
onSeek: audioPlayer.seek(position)
onSourceInError: allListeners.playBackError(source, playerError)
}
ManageMediaPlayerControl {
......
......@@ -70,9 +70,13 @@ QUrl AudioWrapper::source() const
return d->mPlayer.media().canonicalUrl();
}
QString AudioWrapper::error() const
QMediaPlayer::Error AudioWrapper::error() const
{
return d->mPlayer.errorString();
if (d->mPlayer.error() != QMediaPlayer::NoError) {
qDebug() << "AudioWrapper::error" << d->mPlayer.errorString();
}
return d->mPlayer.error();
}
qint64 AudioWrapper::duration() const
......
......@@ -56,7 +56,7 @@ class AudioWrapper : public QObject
READ playbackState
NOTIFY playbackStateChanged)
Q_PROPERTY(QString error
Q_PROPERTY(QMediaPlayer::Error error
READ error
NOTIFY errorChanged)
......@@ -94,7 +94,7 @@ public:
QMediaPlayer::State playbackState() const;
QString error() const;
QMediaPlayer::Error error() const;
qint64 duration() const;
......
......@@ -57,7 +57,7 @@ QUrl ManageAudioPlayer::playerSource() const
return mCurrentTrack.data(mUrlRole).toUrl();
}
int ManageAudioPlayer::playerStatus() const
QMediaPlayer::MediaStatus ManageAudioPlayer::playerStatus() const
{
return mPlayerStatus;
}
......@@ -67,7 +67,7 @@ int ManageAudioPlayer::playerPlaybackState() const
return mPlayerPlaybackState;
}
int ManageAudioPlayer::playerError() const
QMediaPlayer::Error ManageAudioPlayer::playerError() const
{
return mPlayerError;
}
......@@ -150,6 +150,8 @@ void ManageAudioPlayer::setCurrentTrack(const QPersistentModelIndex &currentTrac
restorePreviousState();
}
mPlayerError = QMediaPlayer::NoError;
Q_EMIT currentTrackChanged();
switch (mPlayerPlaybackState) {
......@@ -201,40 +203,41 @@ void ManageAudioPlayer::setIsPlayingRole(int value)
Q_EMIT isPlayingRoleChanged();
}
void ManageAudioPlayer::setPlayerStatus(int playerStatus)
void ManageAudioPlayer::setPlayerStatus(QMediaPlayer::MediaStatus playerStatus)
{
if (mPlayerStatus == playerStatus) {
return;
}
if (playerStatus < static_cast<int>(NoMedia) || playerStatus > static_cast<int>(UnknownStatus)) {
if (playerStatus < static_cast<int>(QMediaPlayer::UnknownMediaStatus) || playerStatus > static_cast<int>(QMediaPlayer::InvalidMedia)) {
return;
}
mPlayerStatus = static_cast<PlayerStatus>(playerStatus);
mPlayerStatus = static_cast<QMediaPlayer::MediaStatus>(playerStatus);
Q_EMIT playerStatusChanged();
switch (mPlayerStatus) {
case NoMedia:
break;
case Loading:
case QMediaPlayer::NoMedia:
break;
case Loaded:
case QMediaPlayer::LoadingMedia:
break;
case Buffering:
case QMediaPlayer::LoadedMedia:
if (mPlayingState) {
triggerPlay();
}
break;
case Stalled:
case QMediaPlayer::BufferingMedia:
break;
case Buffered:
case QMediaPlayer::StalledMedia:
break;
case EndOfMedia:
case QMediaPlayer::BufferedMedia:
break;
case InvalidMedia:
case QMediaPlayer::EndOfMedia:
break;
case UnknownStatus:
case QMediaPlayer::InvalidMedia:
triggerSkipNextTrack();
break;
case QMediaPlayer::UnknownMediaStatus:
break;
}
}
......@@ -255,7 +258,7 @@ void ManageAudioPlayer::setPlayerPlaybackState(int playerPlaybackState)
if (!mSkippingCurrentTrack) {
switch(mPlayerPlaybackState) {
case StoppedState:
if (mPlayerStatus == EndOfMedia || mPlayerStatus == InvalidMedia) {
if (mPlayerStatus == QMediaPlayer::EndOfMedia || mPlayerStatus == QMediaPlayer::InvalidMedia) {
triggerSkipNextTrack();
}
if (mPlayListModel && mCurrentTrack.isValid()) {
......@@ -296,18 +299,18 @@ void ManageAudioPlayer::setPlayerPlaybackState(int playerPlaybackState)
}
}
void ManageAudioPlayer::setPlayerError(int playerError)
void ManageAudioPlayer::setPlayerError(QMediaPlayer::Error playerError)
{
if (mPlayerError == playerError) {
return;
}
if (playerError < static_cast<int>(NoError) || playerError > static_cast<int>(ServiceMissing)) {
return;
}
mPlayerError = static_cast<PlayerErrorState>(playerError);
mPlayerError = playerError;
Q_EMIT playerErrorChanged();
if (mPlayerError != QMediaPlayer::NoError) {
Q_EMIT sourceInError(playerSource(), mPlayerError);
}
}
void ManageAudioPlayer::ensurePlay()
......@@ -322,27 +325,27 @@ void ManageAudioPlayer::playPause()
mPlayingState = !mPlayingState;
switch (mPlayerStatus) {
case Loaded:
case Buffering:
case QMediaPlayer::LoadedMedia:
case QMediaPlayer::BufferingMedia:
case QMediaPlayer::BufferedMedia:
case QMediaPlayer::LoadingMedia:
if (mPlayingState) {
triggerPlay();
} else {
triggerPause();
}
break;
case EndOfMedia:
case QMediaPlayer::EndOfMedia:
if (mPlayerPlaybackState == PlayingState && !mPlayingState) {
triggerPause();
} else if (mPlayerPlaybackState == PausedState && mPlayingState) {
triggerPlay();
}
break;
case NoMedia:
case Loading:
case Stalled:
case Buffered:
case InvalidMedia:
case UnknownStatus:
case QMediaPlayer::NoMedia:
case QMediaPlayer::StalledMedia:
case QMediaPlayer::InvalidMedia:
case QMediaPlayer::UnknownMediaStatus:
break;
}
}
......
......@@ -24,6 +24,7 @@
#include <QPersistentModelIndex>
#include <QAbstractItemModel>
#include <QUrl>
#include <QMediaPlayer>
class ManageAudioPlayer : public QObject
{
......@@ -68,7 +69,7 @@ class ManageAudioPlayer : public QObject
WRITE setIsPlayingRole
NOTIFY isPlayingRoleChanged)
Q_PROPERTY(int playerStatus
Q_PROPERTY(QMediaPlayer::MediaStatus playerStatus
READ playerStatus
WRITE setPlayerStatus
NOTIFY playerStatusChanged)
......@@ -78,7 +79,7 @@ class ManageAudioPlayer : public QObject
WRITE setPlayerPlaybackState
NOTIFY playerPlaybackStateChanged)
Q_PROPERTY(int playerError
Q_PROPERTY(QMediaPlayer::Error playerError
READ playerError
WRITE setPlayerError
NOTIFY playerErrorChanged)
......@@ -110,20 +111,6 @@ class ManageAudioPlayer : public QObject
public:
enum PlayerStatus {
NoMedia = 0,
Loading = NoMedia + 1,
Loaded = Loading + 1,
Buffering = Loaded + 1,
Stalled = Buffering + 1,
Buffered = Stalled + 1,
EndOfMedia = Buffered + 1,
InvalidMedia = EndOfMedia + 1,
UnknownStatus = InvalidMedia + 1,
};
Q_ENUM(PlayerStatus)
enum PlayerPlaybackState {
PlayingState = 1,
PausedState = 2,
......@@ -132,17 +119,6 @@ public:
Q_ENUM(PlayerPlaybackState)
enum PlayerErrorState {
NoError = 0,
ResourceError = NoError + 1,
FormatError = ResourceError + 1,
NetworkError = FormatError + 1,
AccessDenied = NetworkError + 1,
ServiceMissing = AccessDenied + 1,
};
Q_ENUM(PlayerErrorState)
explicit ManageAudioPlayer(QObject *parent = nullptr);
QPersistentModelIndex currentTrack() const;
......@@ -155,11 +131,11 @@ public:
QUrl playerSource() const;
int playerStatus() const;
QMediaPlayer::MediaStatus playerStatus() const;
int playerPlaybackState() const;
int playerError() const;
QMediaPlayer::Error playerError() const;
int audioDuration() const;
......@@ -223,6 +199,8 @@ Q_SIGNALS:
void albumNameRoleChanged();
void sourceInError(QUrl source, QMediaPlayer::Error playerError);
public Q_SLOTS:
void setCurrentTrack(const QPersistentModelIndex &currentTrack);
......@@ -233,11 +211,11 @@ public Q_SLOTS:
void setIsPlayingRole(int value);
void setPlayerStatus(int playerStatus);
void setPlayerStatus(QMediaPlayer::MediaStatus playerStatus);
void setPlayerPlaybackState(int playerPlaybackState);
void setPlayerError(int playerError);
void setPlayerError(QMediaPlayer::Error playerError);
void ensurePlay();
......@@ -297,11 +275,11 @@ private:
QVariant mOldPlayerSource;
PlayerStatus mPlayerStatus = NoMedia;
QMediaPlayer::MediaStatus mPlayerStatus = QMediaPlayer::NoMedia;
PlayerPlaybackState mPlayerPlaybackState = StoppedState;
PlayerErrorState mPlayerError = NoError;
QMediaPlayer::Error mPlayerError = QMediaPlayer::NoError;
bool mPlayingState = false;
......
......@@ -175,6 +175,7 @@ void MusicListenersManager::subscribeForTracks(MediaPlayList *client)
connect(this, &MusicListenersManager::trackRemoved, helper, &TracksListener::trackRemoved);
connect(this, &MusicListenersManager::tracksAdded, helper, &TracksListener::tracksAdded);
connect(this, &MusicListenersManager::trackModified, helper, &TracksListener::trackModified);
connect(this, &MusicListenersManager::removeTracksInError, &d->mDatabaseInterface, &DatabaseInterface::removeTracksList);
connect(helper, &TracksListener::trackHasChanged, client, &MediaPlayList::trackChanged);
connect(helper, &TracksListener::trackHasBeenRemoved, client, &MediaPlayList::trackRemoved);
connect(helper, &TracksListener::albumAdded, client, &MediaPlayList::albumAdded);
......@@ -248,6 +249,15 @@ void MusicListenersManager::setElisaApplication(ElisaApplication *elisaApplicati
emit elisaApplicationChanged();
}
void MusicListenersManager::playBackError(QUrl sourceInError, QMediaPlayer::Error playerError)
{
qDebug() << "MusicListenersManager::playBackError" << sourceInError;
if (playerError == QMediaPlayer::ResourceError) {
Q_EMIT removeTracksInError({sourceInError});
}
}
void MusicListenersManager::configChanged()
{
#if defined KF5Config_FOUND && KF5Config_FOUND
......
......@@ -25,6 +25,8 @@
#include <QObject>
#include <QQmlListProperty>
#include <QMediaPlayer>
#include "musicalbum.h"
#include "musicartist.h"
#include "musicaudiotrack.h"
......@@ -111,6 +113,8 @@ Q_SIGNALS:
void elisaApplicationChanged();
void removeTracksInError(QList<QUrl> tracks);
public Q_SLOTS:
void databaseReady();
......@@ -123,6 +127,8 @@ public Q_SLOTS:
void setElisaApplication(ElisaApplication* elisaApplication);
void playBackError(QUrl sourceInError, QMediaPlayer::Error playerError);
private Q_SLOTS:
void configChanged();
......
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