summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMavridis Philippe <mavridisf@gmail.com>2023-07-07 14:17:37 +0300
committerMavridis Philippe <mavridisf@gmail.com>2023-11-24 22:46:27 +0200
commit6a29a25229092de3e50a4abd7aa9cf6374027b07 (patch)
tree867eb905689183545aa587c7833a300a49604007
parent90feba667b833eca6ff2362af527fe5defa4cff9 (diff)
downloadkaffeine-6a29a25229092de3e50a4abd7aa9cf6374027b07.tar.gz
kaffeine-6a29a25229092de3e50a4abd7aa9cf6374027b07.zip
mpv: fix seeking, EOF and logo display
Signed-off-by: Mavridis Philippe <mavridisf@gmail.com>
-rw-r--r--kaffeine/src/player-parts/libmpv-part/libmpv_event.cpp14
-rw-r--r--kaffeine/src/player-parts/libmpv-part/libmpv_part.cpp39
-rw-r--r--kaffeine/src/player-parts/libmpv-part/libmpv_part.h2
3 files changed, 42 insertions, 13 deletions
diff --git a/kaffeine/src/player-parts/libmpv-part/libmpv_event.cpp b/kaffeine/src/player-parts/libmpv-part/libmpv_event.cpp
index 04b6fdb..aa9e50c 100644
--- a/kaffeine/src/player-parts/libmpv-part/libmpv_event.cpp
+++ b/kaffeine/src/player-parts/libmpv-part/libmpv_event.cpp
@@ -73,8 +73,11 @@ void MpvEventThread::processEvent(mpv_event *event) {
case MPV_EVENT_LOG_MESSAGE: {
struct mpv_event_log_message *msg = (struct mpv_event_log_message *)event->data;
- kdDebug() << "[mpv " << msg->prefix << "] <" << msg->level << ">: "
- << msg->text << endl;
+ TQString text(msg->text);
+ text = text.remove("\n");
+ if (text.isEmpty()) break;
+
+ kdDebug() << "[mpv " << msg->prefix << "] <" << msg->level << ">: " << text << endl;
m_part->setStatusBarText(TQString("MPV %1 (%2): %3").arg(msg->prefix, msg->level, msg->text));
processMessage(msg->prefix, msg->level, msg->text);
@@ -83,6 +86,13 @@ void MpvEventThread::processEvent(mpv_event *event) {
case MPV_EVENT_END_FILE: {
struct mpv_event_end_file *end = (struct mpv_event_end_file *)event->data;
+
+ if (end->reason != MPV_END_FILE_REASON_EOF &&
+ end->reason != MPV_END_FILE_REASON_ERROR) {
+ break;
+ }
+
+ // Track errors
TQString error;
if (end->reason == MPV_END_FILE_REASON_ERROR) {
error = TQString(mpv_error_string(end->error));
diff --git a/kaffeine/src/player-parts/libmpv-part/libmpv_part.cpp b/kaffeine/src/player-parts/libmpv-part/libmpv_part.cpp
index 0c71857..2132dd3 100644
--- a/kaffeine/src/player-parts/libmpv-part/libmpv_part.cpp
+++ b/kaffeine/src/player-parts/libmpv-part/libmpv_part.cpp
@@ -64,6 +64,7 @@ MpvPart::MpvPart(TQWidget* parentWidget, const char* widgetName, TQObject* paren
: KaffeinePart(parent, name ? name : "MpvPart"),
m_current(0),
m_seeking(false),
+ m_seekpos(0),
m_recordFilePath(),
m_context(nullptr),
m_error(nullptr),
@@ -151,7 +152,7 @@ void MpvPart::initActions()
/*** Position toolbar ***/
// Important: we have a max of 1000 instead of 100 for better precision; multiply/divide your percentages by 10
- m_position = new TQSlider(0, 1000, 10, 0, TQt::Horizontal, 0);
+ m_position = new TQSlider(0, 100, 10, 0, TQt::Horizontal, 0);
TQToolTip::add(m_position, i18n("Position"));
m_position->setTracking(false);
m_position->setFocusPolicy(TQ_NoFocus);
@@ -245,8 +246,7 @@ void MpvPart::customEvent(TQCustomEvent *event) {
else if (pe->property() == "percent-pos" && pe->format() == MPV_FORMAT_DOUBLE) {
if (!m_seeking) {
- m_percent = pe->toDouble();
- m_position->setValue(m_percent * 10);
+ m_position->setValue(pe->toDouble());
}
}
@@ -262,6 +262,11 @@ void MpvPart::customEvent(TQCustomEvent *event) {
else if (event->type() == MPVPART_EVENT_EOF) {
resetTime();
+ if (!m_mrl.isEmpty()) {
+ closeURL();
+ stateChanged("not_playing");
+ }
+
MpvEOFEvent *eofe = (MpvEOFEvent *)event;
if (eofe->reason() == MPV_END_FILE_REASON_ERROR) {
KMessageBox::detailedError(nullptr, i18n("Cannot play file."), eofe->error());
@@ -485,6 +490,7 @@ void MpvPart::resetTime() {
void MpvPart::slotStartSeeking() {
if (!isSeekable()) {
+ kdWarning() << "current file not seekable!" << endl;
emit setStatusBarText( i18n("Cannot seek current file!") );
return;
}
@@ -493,13 +499,26 @@ void MpvPart::slotStartSeeking() {
}
void MpvPart::slotStopSeeking() {
- slotSetPosition(m_percent);
+ if (!m_seeking) return;
+
+ slotSetPosition(m_seekpos);
slotPause(false);
m_seeking = false;
}
-void MpvPart::slotSetSeekingPos(int pos) {
- m_percent = (uint)pos / 10;
+void MpvPart::slotSetSeekingPos(int percent) {
+ if (!m_seeking) return;
+
+ // Compute current position and update playtime indicator
+ TQTime duration = m_mrl.length();
+ uint secs = (duration.hour() * 60 * 60) +
+ (duration.minute() * 60) +
+ duration.second();
+
+ m_seekpos = secs * percent / 100;
+
+ TQTime pos; pos = pos.addSecs(m_seekpos);
+ updatePlaytime(pos);
}
uint MpvPart::volume() const {
@@ -509,7 +528,7 @@ uint MpvPart::volume() const {
}
uint MpvPart::position() const {
- return m_percent;
+ return m_position->value();
}
void MpvPart::slotSetVolume(uint volume) {
@@ -519,11 +538,11 @@ void MpvPart::slotSetVolume(uint volume) {
mpv_set_property(m_mpv, "ao-volume", MPV_FORMAT_INT64, &value);
}
-void MpvPart::slotSetPosition(uint position) {
+void MpvPart::slotSetPosition(uint secs) {
if (!m_mpv) return;
- int64_t value = (int64_t)position;
- mpv_set_property(m_mpv, "percent-pos", MPV_FORMAT_INT64, &value);
+ int64_t value = (int64_t)secs;
+ mpv_set_property(m_mpv, "time-pos", MPV_FORMAT_INT64, &value);
}
void MpvPart::slotPrevious() {
diff --git a/kaffeine/src/player-parts/libmpv-part/libmpv_part.h b/kaffeine/src/player-parts/libmpv-part/libmpv_part.h
index e2204d6..3350d78 100644
--- a/kaffeine/src/player-parts/libmpv-part/libmpv_part.h
+++ b/kaffeine/src/player-parts/libmpv-part/libmpv_part.h
@@ -163,7 +163,7 @@ class MpvPart : public KaffeinePart
uint m_current;
TQTime m_time;
- uint m_percent;
+ uint m_seekpos;
bool m_seeking;
TQString m_recordFilePath;
};