Make PlayerManager work

Still one issue with the minimized player opening on startup
This commit is contained in:
Bart De Vries 2021-04-11 16:19:58 +02:00
parent 7d94792872
commit 3aa4b836d2
4 changed files with 54 additions and 11 deletions

View File

@ -20,6 +20,7 @@ private:
QMediaPlayer mPlayer; QMediaPlayer mPlayer;
Entry* entry = nullptr; Entry* entry = nullptr;
bool playerOpen = false;
friend class AudioManager; friend class AudioManager;
@ -50,6 +51,11 @@ Entry* AudioManager::entry () const
return d->entry; return d->entry;
} }
bool AudioManager::playerOpen() const
{
return d->playerOpen;
}
bool AudioManager::muted() const bool AudioManager::muted() const
{ {
return d->mPlayer.isMuted(); return d->mPlayer.isMuted();
@ -108,6 +114,12 @@ void AudioManager::setEntry(Entry* entry)
Q_EMIT entryChanged(); Q_EMIT entryChanged();
} }
void AudioManager::setPlayerOpen(bool state)
{
d->playerOpen = state;
Q_EMIT playerOpenChanged();
}
void AudioManager::setMuted(bool muted) void AudioManager::setMuted(bool muted)
{ {
d->mPlayer.setMuted(muted); d->mPlayer.setMuted(muted);

View File

@ -22,7 +22,9 @@ class AudioManager : public QObject
Q_OBJECT Q_OBJECT
Q_PROPERTY(bool playerOpen Q_PROPERTY(bool playerOpen
MEMBER playerOpen) READ playerOpen
WRITE setPlayerOpen
NOTIFY playerOpenChanged)
Q_PROPERTY(Entry* entry Q_PROPERTY(Entry* entry
READ entry READ entry
@ -71,6 +73,8 @@ class AudioManager : public QObject
public: public:
explicit AudioManager(QObject *parent = nullptr);
static AudioManager &instance() static AudioManager &instance()
{ {
static AudioManager _instance; static AudioManager _instance;
@ -81,6 +85,8 @@ public:
[[nodiscard]] Entry* entry() const; [[nodiscard]] Entry* entry() const;
[[nodiscard]] bool playerOpen() const;
[[nodiscard]] bool muted() const; [[nodiscard]] bool muted() const;
[[nodiscard]] qreal volume() const; [[nodiscard]] qreal volume() const;
@ -101,6 +107,8 @@ public:
Q_SIGNALS: Q_SIGNALS:
void playerOpenChanged();
void entryChanged(); void entryChanged();
void mutedChanged(bool muted); void mutedChanged(bool muted);
@ -131,6 +139,8 @@ public Q_SLOTS:
void setEntry(Entry* entry); void setEntry(Entry* entry);
void setPlayerOpen(bool state);
void setMuted(bool muted); void setMuted(bool muted);
void setVolume(qreal volume); void setVolume(qreal volume);
@ -159,12 +169,8 @@ private Q_SLOTS:
private: private:
explicit AudioManager(QObject *parent = nullptr);
friend class AudioManagerPrivate; friend class AudioManagerPrivate;
std::unique_ptr<AudioManagerPrivate> d; std::unique_ptr<AudioManagerPrivate> d;
bool playerOpen;
}; };

View File

@ -68,10 +68,12 @@ int main(int argc, char *argv[])
engine->setObjectOwnership(SettingsManager::self(), QQmlEngine::CppOwnership); engine->setObjectOwnership(SettingsManager::self(), QQmlEngine::CppOwnership);
return SettingsManager::self(); return SettingsManager::self();
}); });
qmlRegisterSingletonType<AudioManager>("org.kde.alligator", 1, 0, "AudioManager", [](QQmlEngine *engine, QJSEngine *) -> QObject * { /*qmlRegisterSingletonType<AudioManager>("org.kde.alligator", 1, 0, "AudioManager", [](QQmlEngine *engine, QJSEngine *) -> QObject * {
engine->setObjectOwnership(&AudioManager::instance(), QQmlEngine::CppOwnership); engine->setObjectOwnership(&AudioManager::instance(), QQmlEngine::CppOwnership);
return &AudioManager::instance(); return &AudioManager::instance();
}); });*/
qmlRegisterType<AudioManager>("org.kde.alligator", 1, 0, "AudioManager");
qRegisterMetaType<Entry*>("const Entry*"); // "hack" to make qml understand Entry* qRegisterMetaType<Entry*>("const Entry*"); // "hack" to make qml understand Entry*
QQmlApplicationEngine engine; QQmlApplicationEngine engine;
@ -98,6 +100,8 @@ int main(int argc, char *argv[])
DataManager::instance(); DataManager::instance();
//AudioManager::instance();
engine.load(QUrl(QStringLiteral("qrc:///main.qml"))); engine.load(QUrl(QStringLiteral("qrc:///main.qml")));
if (engine.rootObjects().isEmpty()) { if (engine.rootObjects().isEmpty()) {

View File

@ -60,6 +60,12 @@ Kirigami.ApplicationWindow {
] ]
} }
AudioManager {
id: audio
playerOpen: false
source: entry ? (entry.enclosure ? "file://" + entry.enclosure.path : "") : ""
}
Component { Component {
id: aboutPage id: aboutPage
Kirigami.AboutPage { Kirigami.AboutPage {
@ -79,19 +85,34 @@ Kirigami.ApplicationWindow {
id: queueList id: queueList
} }
/*
Audio { Audio {
id: audio id: audio
property var entry: SettingsManager.lastPlayingEntry !== "none" ? DataManager.getEntry(SettingsManager.lastPlayingEntry) : undefined property var entry: SettingsManager.lastPlayingEntry !== "none" ? DataManager.getEntry(SettingsManager.lastPlayingEntry) : undefined
property bool playerOpen: false property bool playerOpen: false
onEntryChanged: SettingsManager.lastPlayingEntry = entry.id onSourceChanged: {
source: entry ? (entry.enclosure ? "file://" + entry.enclosure.path : "") : "" if (entry !== undefined) {
console.log("Changed track")
SettingsManager.lastPlayingEntry = entry.id
console.log("Between pause and seek", entry.title)
seek(entry.enclosure.playPosition)
}
}
onPositionChanged: {
if (playbackState == Audio.PlayingState) {
entry.enclosure.playPosition = position
}
console.log(entry.title, position, playbackState)
}
//source: entry ? (entry.enclosure ? "file://" + entry.enclosure.path : "") : ""
//source: entry.enclosure.url //source: entry.enclosure.url
onError: console.debug(errorString) onError: console.debug(errorString)
//source: "gst-pipeline: playbin uri=file://" + entry.enclosure.path + " audio_sink=\"scaletempo ! audioconvert ! audioresample ! autoaudiosink\" video_sink=\"fakevideosink\"" source: "gst-pipeline: playbin uri=file://" + entry.enclosure.path + " audio_sink=\"scaletempo ! audioconvert ! audioresample ! autoaudiosink\" video_sink=\"fakevideosink\""
} }
*/
footer: Loader { footer: Loader {
active: (audio.entry !== undefined) && !audio.playerOpen active: (audio.entry !== undefined) && !audio.playerOpen