mirror of https://github.com/KDE/kasts.git
Make PlayerManager work
Still one issue with the minimized player opening on startup
This commit is contained in:
parent
7d94792872
commit
3aa4b836d2
|
@ -20,6 +20,7 @@ private:
|
|||
QMediaPlayer mPlayer;
|
||||
|
||||
Entry* entry = nullptr;
|
||||
bool playerOpen = false;
|
||||
|
||||
friend class AudioManager;
|
||||
|
||||
|
@ -50,6 +51,11 @@ Entry* AudioManager::entry () const
|
|||
return d->entry;
|
||||
}
|
||||
|
||||
bool AudioManager::playerOpen() const
|
||||
{
|
||||
return d->playerOpen;
|
||||
}
|
||||
|
||||
bool AudioManager::muted() const
|
||||
{
|
||||
return d->mPlayer.isMuted();
|
||||
|
@ -108,6 +114,12 @@ void AudioManager::setEntry(Entry* entry)
|
|||
Q_EMIT entryChanged();
|
||||
}
|
||||
|
||||
void AudioManager::setPlayerOpen(bool state)
|
||||
{
|
||||
d->playerOpen = state;
|
||||
Q_EMIT playerOpenChanged();
|
||||
}
|
||||
|
||||
void AudioManager::setMuted(bool muted)
|
||||
{
|
||||
d->mPlayer.setMuted(muted);
|
||||
|
|
|
@ -22,7 +22,9 @@ class AudioManager : public QObject
|
|||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(bool playerOpen
|
||||
MEMBER playerOpen)
|
||||
READ playerOpen
|
||||
WRITE setPlayerOpen
|
||||
NOTIFY playerOpenChanged)
|
||||
|
||||
Q_PROPERTY(Entry* entry
|
||||
READ entry
|
||||
|
@ -71,6 +73,8 @@ class AudioManager : public QObject
|
|||
|
||||
public:
|
||||
|
||||
explicit AudioManager(QObject *parent = nullptr);
|
||||
|
||||
static AudioManager &instance()
|
||||
{
|
||||
static AudioManager _instance;
|
||||
|
@ -81,6 +85,8 @@ public:
|
|||
|
||||
[[nodiscard]] Entry* entry() const;
|
||||
|
||||
[[nodiscard]] bool playerOpen() const;
|
||||
|
||||
[[nodiscard]] bool muted() const;
|
||||
|
||||
[[nodiscard]] qreal volume() const;
|
||||
|
@ -101,6 +107,8 @@ public:
|
|||
|
||||
Q_SIGNALS:
|
||||
|
||||
void playerOpenChanged();
|
||||
|
||||
void entryChanged();
|
||||
|
||||
void mutedChanged(bool muted);
|
||||
|
@ -131,6 +139,8 @@ public Q_SLOTS:
|
|||
|
||||
void setEntry(Entry* entry);
|
||||
|
||||
void setPlayerOpen(bool state);
|
||||
|
||||
void setMuted(bool muted);
|
||||
|
||||
void setVolume(qreal volume);
|
||||
|
@ -159,12 +169,8 @@ private Q_SLOTS:
|
|||
|
||||
private:
|
||||
|
||||
explicit AudioManager(QObject *parent = nullptr);
|
||||
|
||||
friend class AudioManagerPrivate;
|
||||
|
||||
std::unique_ptr<AudioManagerPrivate> d;
|
||||
|
||||
bool playerOpen;
|
||||
|
||||
};
|
||||
|
|
|
@ -68,10 +68,12 @@ int main(int argc, char *argv[])
|
|||
engine->setObjectOwnership(SettingsManager::self(), QQmlEngine::CppOwnership);
|
||||
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);
|
||||
return &AudioManager::instance();
|
||||
});
|
||||
});*/
|
||||
qmlRegisterType<AudioManager>("org.kde.alligator", 1, 0, "AudioManager");
|
||||
|
||||
qRegisterMetaType<Entry*>("const Entry*"); // "hack" to make qml understand Entry*
|
||||
|
||||
QQmlApplicationEngine engine;
|
||||
|
@ -98,6 +100,8 @@ int main(int argc, char *argv[])
|
|||
|
||||
DataManager::instance();
|
||||
|
||||
//AudioManager::instance();
|
||||
|
||||
engine.load(QUrl(QStringLiteral("qrc:///main.qml")));
|
||||
|
||||
if (engine.rootObjects().isEmpty()) {
|
||||
|
|
|
@ -60,6 +60,12 @@ Kirigami.ApplicationWindow {
|
|||
]
|
||||
}
|
||||
|
||||
AudioManager {
|
||||
id: audio
|
||||
playerOpen: false
|
||||
source: entry ? (entry.enclosure ? "file://" + entry.enclosure.path : "") : ""
|
||||
}
|
||||
|
||||
Component {
|
||||
id: aboutPage
|
||||
Kirigami.AboutPage {
|
||||
|
@ -79,19 +85,34 @@ Kirigami.ApplicationWindow {
|
|||
id: queueList
|
||||
}
|
||||
|
||||
/*
|
||||
Audio {
|
||||
id: audio
|
||||
|
||||
property var entry: SettingsManager.lastPlayingEntry !== "none" ? DataManager.getEntry(SettingsManager.lastPlayingEntry) : undefined
|
||||
property bool playerOpen: false
|
||||
|
||||
onEntryChanged: SettingsManager.lastPlayingEntry = entry.id
|
||||
source: entry ? (entry.enclosure ? "file://" + entry.enclosure.path : "") : ""
|
||||
//source: entry.enclosure.url
|
||||
onError: console.debug(errorString)
|
||||
//source: "gst-pipeline: playbin uri=file://" + entry.enclosure.path + " audio_sink=\"scaletempo ! audioconvert ! audioresample ! autoaudiosink\" video_sink=\"fakevideosink\""
|
||||
onSourceChanged: {
|
||||
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
|
||||
onError: console.debug(errorString)
|
||||
source: "gst-pipeline: playbin uri=file://" + entry.enclosure.path + " audio_sink=\"scaletempo ! audioconvert ! audioresample ! autoaudiosink\" video_sink=\"fakevideosink\""
|
||||
}
|
||||
*/
|
||||
|
||||
footer: Loader {
|
||||
active: (audio.entry !== undefined) && !audio.playerOpen
|
||||
|
|
Loading…
Reference in New Issue