From a4957d6219141f99366d9ef1d14c55fa5e4a2d6f Mon Sep 17 00:00:00 2001 From: NamedKitten Date: Tue, 16 Oct 2018 11:07:14 +0100 Subject: [PATCH] Make player stop after playback finished. Make window title same as media title. --- src/mpvobject.cpp | 26 ++++++++++++++------------ src/qml/main.qml | 7 +++++-- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/mpvobject.cpp b/src/mpvobject.cpp index 15d603f..c63aaaf 100644 --- a/src/mpvobject.cpp +++ b/src/mpvobject.cpp @@ -177,12 +177,22 @@ MpvObject::MpvObject(QQuickItem * parent) #ifndef USE_RENDER mpv::qt::set_option_variant(mpv, "vo", "opengl-cb"); #endif + + // Enable default bindings, because we're lazy. Normally, a player using + // mpv as backend would implement its own key bindings. + mpv_set_option_string(mpv, "input-default-bindings", "yes"); + + // Enable keyboard input on the X11 window. For the messy details, see + // --input-vo-keyboard on the manpage. + mpv_set_option_string(mpv, "input-vo-keyboard", "yes"); + // Fix? mpv::qt::set_option_variant(mpv, "ytdl", "yes"); mpv_set_option_string(mpv, "input-default-bindings", "yes"); mpv_set_option_string(mpv, "input-vo-keyboard", "yes"); + mpv::qt::set_option_variant(mpv, "idle", "once"); mpv::qt::set_option_variant(mpv, "hwdec", "off"); @@ -319,24 +329,16 @@ void MpvObject::handle_mpv_event(mpv_event *event) if (prop->format == MPV_FORMAT_STRING) { QMetaObject::invokeMethod(this,"setTitle"); } - } else if (strcmp(prop->name, "chapter-list") == 0 || strcmp(prop->name, "track-list") == 0) { - if (prop->format == MPV_FORMAT_NODE) { - /* - QVariant v = mpv::qt::node_to_variant((mpv_node *)prop->data); - // Abuse JSON support for easily printing the mpv_node contents. - QJsonDocument d = QJsonDocument::fromVariant(v); - printf("Change property %s:\n", QString(prop->name).toStdString().c_str()); - printf(d.toJson().data());*/ - //QMetaObject::invokeMethod(this,"updatePlaylist"); - } } break; } case MPV_EVENT_SHUTDOWN: { exit(0); + break; + } + default: { + break; } - default: ; - // Ignore uninteresting or unknown events. } } diff --git a/src/qml/main.qml b/src/qml/main.qml index e813bc4..253381e 100644 --- a/src/qml/main.qml +++ b/src/qml/main.qml @@ -9,7 +9,7 @@ import "codes.js" as LanguageCodes Window { id: mainWindow - title: "Qt Quick Controls 2" + title: titleLabel.text visible: true width: 720 height: 480 @@ -189,6 +189,7 @@ Window { } function hideControls() { + renderer.setOption("sub-margin-y", "22") controlsBar.visible = false controlsBackground.visible = false titleBar.visible = false @@ -197,6 +198,7 @@ Window { function showControls() { updateControls() + renderer.setOption("sub-margin-y", String(controlsBar.height + progressBar.height)) controlsBar.visible = true controlsBackground.visible = true titleBar.visible = true @@ -249,7 +251,7 @@ Window { onClicked: loadDialog.open() Timer { id: mouseAreaPlayerTimer - interval: 2000 + interval: 1000 running: false repeat: false onTriggered: { @@ -477,6 +479,7 @@ Window { color: "red" border.color: "red" } + } Button {