mpv: fix seeking, EOF and logo display

Signed-off-by: Mavridis Philippe <mavridisf@gmail.com>
feat/libmpv-backend
Mavridis Philippe 11 months ago
parent 90feba667b
commit 6a29a25229
No known key found for this signature in database
GPG Key ID: 93F66F98F906147D

@ -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));

@ -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() {

@ -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;
};

Loading…
Cancel
Save