Autoload last-played book at last-saved place, paused.
Fix graphical spacing glitch in Now Playing beneath playback controls
This commit is contained in:
parent
abaa35d85a
commit
5daba546a1
5 changed files with 60 additions and 33 deletions
|
|
@ -94,12 +94,10 @@ Item {
|
|||
|
||||
if( !MPV.loaded )
|
||||
return console.log("Manager.play(): Cannot play. MPV isn't loaded/ready.");
|
||||
|
||||
/*
|
||||
if( !MPV.loaded )
|
||||
return bookPlay(m_currentBook["id"]);
|
||||
*/
|
||||
console.log(`play()`);
|
||||
return MPV.play();
|
||||
}
|
||||
|
||||
|
|
@ -125,38 +123,25 @@ Item {
|
|||
}
|
||||
|
||||
// Library functions:
|
||||
function bookPlay(bookid, position) {
|
||||
if( m_currentBook && m_currentBook["id"] === bookid)
|
||||
{
|
||||
if( position )
|
||||
setPosition(position);
|
||||
|
||||
return play();
|
||||
}
|
||||
|
||||
function bookLoad(bookid, onLoad, autoplay) {
|
||||
for( let book of manager.m_library )
|
||||
{
|
||||
if( book["id"] === bookid )
|
||||
{
|
||||
MPV.paused = false;
|
||||
MPV.paused = true;
|
||||
MPV.stop();
|
||||
|
||||
let thenPlay = function() {
|
||||
if( !position )
|
||||
position = book["position"];
|
||||
let onLoaded = function() {
|
||||
MPV.loadedChanged.disconnect(onLoaded);
|
||||
MPV.position = book["position"];
|
||||
|
||||
let onLoad = function() {
|
||||
if( !MPV.loaded )
|
||||
return;
|
||||
if( onLoad )
|
||||
onLoad();
|
||||
};
|
||||
|
||||
if( position )
|
||||
MPV.position = position;
|
||||
|
||||
MPV.loadedChanged.disconnect(onLoad);
|
||||
MPV.play();
|
||||
};
|
||||
MPV.loadedChanged.connect(onLoad);
|
||||
MPV.load(book["path"]);
|
||||
let onBookPrepared = function() {
|
||||
MPV.loadedChanged.connect(onLoaded);
|
||||
MPV.load(book["path"], autoplay);
|
||||
}
|
||||
|
||||
m_currentBook = book;
|
||||
|
|
@ -171,21 +156,49 @@ Item {
|
|||
if( success )
|
||||
m_currentBook["artUrl"] = newUrl;
|
||||
|
||||
thenPlay();
|
||||
onBookPrepared();
|
||||
Qt.callLater( function() {
|
||||
thumber.destroy();
|
||||
});
|
||||
});
|
||||
} else {
|
||||
thenPlay();
|
||||
onBookPrepared();
|
||||
}
|
||||
|
||||
settings.setValue("lastbookid", book["id"]);
|
||||
settings.sync();
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
console.warn(`Couldn't find book with ID ${bookid}!`);
|
||||
}
|
||||
|
||||
function bookPlay(bookid, position) {
|
||||
if( m_currentBook && m_currentBook["id"] === bookid)
|
||||
{
|
||||
if( position )
|
||||
setPosition(position);
|
||||
|
||||
return play();
|
||||
}
|
||||
|
||||
let onLoad = function() {
|
||||
if( !MPV.loaded )
|
||||
return;
|
||||
|
||||
if( !position )
|
||||
position = book["position"];
|
||||
|
||||
if( position )
|
||||
MPV.position = position;
|
||||
|
||||
play();
|
||||
};
|
||||
|
||||
return bookLoad(bookid, onLoad, true);
|
||||
}
|
||||
|
||||
Component {
|
||||
id: thumbnail
|
||||
Image {
|
||||
|
|
@ -390,6 +403,7 @@ Item {
|
|||
|
||||
MPV.playingChanged.connect( function() {
|
||||
manager.playing = MPV.playing;
|
||||
console.log(`MPV.playing => ${MPV.playing}`);
|
||||
|
||||
Qt.callLater( function() {
|
||||
ScreenOps.setInhibited(MPV.playing && !MPV.paused, MPV.mediaTitle);
|
||||
|
|
|
|||
|
|
@ -198,7 +198,7 @@ Kirigami.Page {
|
|||
} // ColumnLayout (player controls)
|
||||
|
||||
ColumnLayout {
|
||||
visible: buttonStartResume.visible || buttonStartOver.visible
|
||||
Layout.preferredHeight: buttonStartResume.visible || buttonStartOver.visible ? implicitHeight : 0
|
||||
Layout.preferredWidth: parent.width * 0.75
|
||||
Layout.alignment: Qt.AlignHCenter
|
||||
spacing: Kirigami.Units.largeSpacing
|
||||
|
|
@ -207,6 +207,7 @@ Kirigami.Page {
|
|||
id: buttonStartResume
|
||||
visible: !nowPlayingPageItem.isPlaying
|
||||
display: QQC2.AbstractButton.TextUnderIcon
|
||||
Layout.preferredHeight: visible ? implicitHeight : 0
|
||||
Layout.fillWidth: true
|
||||
text: atStart ? qsTr("Start Book") : qsTr("Resume")
|
||||
icon.name: "media-playback-start"
|
||||
|
|
@ -217,6 +218,7 @@ Kirigami.Page {
|
|||
QQC2.Button {
|
||||
id: buttonStartOver
|
||||
display: QQC2.AbstractButton.TextUnderIcon
|
||||
Layout.preferredHeight: visible ? implicitHeight : 0
|
||||
visible: nowPlayingPageItem.isPlaying ?
|
||||
manager.m_currentBook["position"] > (manager.m_currentBook["length"] - 10)
|
||||
: nowPlayingPageItem.m_book["position"] > (nowPlayingPageItem.m_book["length"] - 10)
|
||||
|
|
|
|||
11
qml/main.qml
11
qml/main.qml
|
|
@ -3,7 +3,6 @@
|
|||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
|
||||
import QtCore
|
||||
|
||||
import QtQuick
|
||||
import QtQuick.Controls as QQC2
|
||||
import QtQuick.Layouts
|
||||
|
|
@ -20,6 +19,10 @@ Kirigami.ApplicationWindow {
|
|||
|
||||
property bool showingNowPlaying: true
|
||||
|
||||
Settings {
|
||||
id: settings
|
||||
}
|
||||
|
||||
Manager {
|
||||
id: manager
|
||||
|
||||
|
|
@ -34,6 +37,12 @@ Kirigami.ApplicationWindow {
|
|||
|
||||
// TODO: This is a dumb hack. Our "initialPage" is Library.
|
||||
root.showingNowPlaying = false;
|
||||
|
||||
const lastbook = settings.value("lastbookid");
|
||||
console.log(`Resume book ID: ${lastbook}`);
|
||||
if( lastbook ) {
|
||||
manager.bookLoad(parseInt(""+lastbook), false, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -337,7 +337,7 @@ QVariantList MpvAudio::nodeToList(const mpv_node &n) {
|
|||
|
||||
/*** Controls ***/
|
||||
|
||||
void MpvAudio::load(const QUrl &url) {
|
||||
void MpvAudio::load(const QUrl &url, bool autoplay) {
|
||||
if( !m_mpv ) return;
|
||||
|
||||
const QString s = url.isLocalFile() ? url.toLocalFile() : url.toString();
|
||||
|
|
@ -346,8 +346,10 @@ void MpvAudio::load(const QUrl &url) {
|
|||
return;
|
||||
}
|
||||
|
||||
QByteArray aps = autoplay ? QString("pause=no").toUtf8() : QString("pause=yes").toUtf8();
|
||||
|
||||
QByteArray u8 = s.toUtf8();
|
||||
const char *cmd[] = { "loadfile", u8.constData(), "replace", nullptr };
|
||||
const char *cmd[] = { "loadfile", u8.constData(), "replace", aps.constData(), nullptr };
|
||||
int r = mpv_command(m_mpv, cmd);
|
||||
if( r < 0 )
|
||||
emit errorOccurred(QStringLiteral("MpvAudio::load failed: %1").arg(QString::fromUtf8(mpv_error_string(r))));
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ public:
|
|||
explicit MpvAudio(QObject *parent = nullptr);
|
||||
~MpvAudio() override;
|
||||
|
||||
Q_INVOKABLE void load(const QUrl &url);
|
||||
Q_INVOKABLE void load(const QUrl &url, bool autoplay=true);
|
||||
Q_INVOKABLE void play();
|
||||
Q_INVOKABLE void pause();
|
||||
Q_INVOKABLE void togglePause();
|
||||
|
|
|
|||
Loading…
Reference in a new issue