diff --git a/src/MpvPlayerBackend.cpp b/src/MpvPlayerBackend.cpp index dff369a..57929f4 100644 --- a/src/MpvPlayerBackend.cpp +++ b/src/MpvPlayerBackend.cpp @@ -329,6 +329,17 @@ MpvPlayerBackend::on_mpv_events() } } +void +MpvPlayerBackend::updateDurationStringText() +{ + findChild("timeLabel") + ->setProperty("text", + QString("%1 / %2 (%3x)") + .arg(createTimestamp(getProperty("time-pos")).toString(), + createTimestamp(getProperty("duration")).toString(), + getProperty("speed").toString())); +} + void MpvPlayerBackend::handle_mpv_event(mpv_event* event) { @@ -338,15 +349,13 @@ MpvPlayerBackend::handle_mpv_event(mpv_event* event) if (strcmp(prop->name, "time-pos") == 0) { if (prop->format == MPV_FORMAT_DOUBLE) { double time = *(double*)prop->data; - QMetaObject::invokeMethod( - this, "setProgressBarValue", Q_ARG(QVariant, time)); + updateDurationStringText(); + findChild("progressBar")->setProperty("value", time); } } else if (strcmp(prop->name, "duration") == 0) { if (prop->format == MPV_FORMAT_DOUBLE) { double time = *(double*)prop->data; - Q_ARG(QVariant, "txt1"), - QMetaObject::invokeMethod( - this, "setProgressBarEnd", Q_ARG(QVariant, time)); + findChild("progressBar")->setProperty("to", time); } } else if (strcmp(prop->name, "volume") == 0) { if (prop->format == MPV_FORMAT_DOUBLE) { @@ -363,13 +372,12 @@ MpvPlayerBackend::handle_mpv_event(mpv_event* event) } else if (strcmp(prop->name, "media-title") == 0) { if (prop->format == MPV_FORMAT_STRING) { char* title = *(char**)prop->data; - QMetaObject::invokeMethod(this, "setTitle", Q_ARG(QVariant, title)); + findChild("titleLabel")->setProperty("text", title); } } else if (strcmp(prop->name, "sub-text") == 0) { if (prop->format == MPV_FORMAT_STRING) { char* subs = *(char**)prop->data; - QMetaObject::invokeMethod( - this, "setSubtitles", Q_ARG(QVariant, subs)); + findChild("nativeSubs")->setProperty("text", subs); } } else if (strcmp(prop->name, "demuxer-cache-duration") == 0) { if (prop->format == MPV_FORMAT_DOUBLE) { diff --git a/src/MpvPlayerBackend.h b/src/MpvPlayerBackend.h index 700b58a..f1e9dba 100644 --- a/src/MpvPlayerBackend.h +++ b/src/MpvPlayerBackend.h @@ -37,6 +37,7 @@ public slots: void prevPlaylistItem(); void nextPlaylistItem(); void toggleOnTop(); + void updateDurationStringText(); QVariant getTracks() const; QVariant getTrack(const QString& track); diff --git a/src/qml/main.qml b/src/qml/main.qml index fea84e2..37a3abc 100644 --- a/src/qml/main.qml +++ b/src/qml/main.qml @@ -168,18 +168,6 @@ ApplicationWindow { } } - function setProgressBarEnd(val) { - progressBar.to = val - } - - function setProgressBarValue(val) { - progressBar.value = val - timeLabel.text = player.createTimestamp( - val) + " / " + player.createTimestamp( - progressBar.to) + " (" + parseFloat( - player.getProperty("speed").toFixed(2)) + "x)" - } - function skipToNinth(val) { var skipto = 0 if (val != 0) { @@ -226,14 +214,6 @@ ApplicationWindow { } } - function setTitle(title) { - titleLabel.text = title - } - - function setSubtitles(subs) { - nativeSubs.text = subs - } - function isAnyMenuOpen() { return settingsMenu.visible || fileMenuBarItem.opened || playbackMenuBarItem.opened || viewMenuBarItem.opened @@ -864,6 +844,7 @@ ApplicationWindow { Text { id: titleLabel + objectName: "titleLabel" text: translate.getTranslation("TITLE", i18n.language) color: "white" width: parent.width @@ -926,6 +907,7 @@ ApplicationWindow { Label { id: nativeSubs + objectName: "nativeSubs" onWidthChanged: { if (width > parent.width - 10) @@ -990,6 +972,7 @@ ApplicationWindow { Slider { id: progressBar + objectName: "progressBar" to: 1 value: 0.0 anchors.bottom: parent.top @@ -1206,6 +1189,7 @@ ApplicationWindow { Text { id: timeLabel + objectName: "timeLabel" text: "0:00 / 0:00" color: "white" anchors.left: volumeBar.right