1
0
Fork 0

[UI+Backend] Improved time string events and fixed niconico icons.

I made creating time string way more efficient by saving old values and comparing
them because they can change multiple times per second but the duration string only
needs to update once per second and it also needs to always update when speed changes.
TODO: Add speed event to allow speed to be updated when paused.
This commit is contained in:
NamedKitten 2018-11-30 08:21:34 +00:00
parent da68c65faf
commit 5a5674b832
6 changed files with 61 additions and 20 deletions

View file

@ -471,13 +471,31 @@ DirectMpvPlayerBackend::on_mpv_events()
} }
void void
DirectMpvPlayerBackend::updateDurationString() DirectMpvPlayerBackend::updateDurationString(int numTime)
{ {
emit durationStringChanged( QVariant speed = getProperty("speed");
QString("%1 / %2 (%3x)") QMetaMethod metaMethod = sender()->metaObject()->method(senderSignalIndex());
.arg(Utils::createTimestamp(getProperty("time-pos").toInt()), if (metaMethod.name() == "positionChanged") {
totalDurationString, if (speed != lastSpeed) {
getProperty("speed").toString())); lastSpeed = speed.toDouble();
} else {
if (numTime == lastTime) {
return;
}
}
lastTime = numTime;
lastPositionString = Utils::createTimestamp(lastTime);
} else if (metaMethod.name() == "durationChanged") {
totalDurationString = Utils::createTimestamp(numTime);
}
QString durationString;
durationString += lastPositionString;
durationString += " / ";
durationString += totalDurationString;
if (lastSpeed != 1) {
durationString += " (" + speed.toString() + "x)";
}
emit durationStringChanged(durationString);
} }
void void
@ -518,13 +536,12 @@ DirectMpvPlayerBackend::handle_mpv_event(mpv_event* event)
if (prop->format == MPV_FORMAT_DOUBLE) { if (prop->format == MPV_FORMAT_DOUBLE) {
double time = *(double*)prop->data; double time = *(double*)prop->data;
emit positionChanged(time); emit positionChanged(time);
Utils::ResetScreensaver();
} }
} else if (strcmp(prop->name, "duration") == 0) { } else if (strcmp(prop->name, "duration") == 0) {
if (prop->format == MPV_FORMAT_DOUBLE) { if (prop->format == MPV_FORMAT_DOUBLE) {
double time = *(double*)prop->data; double time = *(double*)prop->data;
totalDurationString = Utils::createTimestamp(time);
emit durationChanged(time); emit durationChanged(time);
Utils::ResetScreensaver();
} }
} else if (strcmp(prop->name, "mute") == 0 || } else if (strcmp(prop->name, "mute") == 0 ||
strcmp(prop->name, "volume") == 0) { strcmp(prop->name, "volume") == 0) {

View file

@ -42,7 +42,10 @@ class DirectMpvPlayerBackend
mpv_opengl_cb_context* mpv_gl; mpv_opengl_cb_context* mpv_gl;
MpvRenderer* renderer; MpvRenderer* renderer;
bool onTop = false; bool onTop = false;
int lastTime = 0;
double lastSpeed = 0;
QString totalDurationString; QString totalDurationString;
QString lastPositionString;
public: public:
static void on_update(void* ctx); static void on_update(void* ctx);
@ -92,7 +95,7 @@ signals:
private slots: private slots:
void doUpdate(); void doUpdate();
void on_mpv_events(); void on_mpv_events();
void updateDurationString(); void updateDurationString(int numTime);
void handleWindowChanged(QQuickWindow* win); void handleWindowChanged(QQuickWindow* win);
private: private:

View file

@ -449,13 +449,31 @@ MpvPlayerBackend::on_mpv_events()
} }
void void
MpvPlayerBackend::updateDurationString() MpvPlayerBackend::updateDurationString(int numTime)
{ {
emit durationStringChanged( QVariant speed = getProperty("speed");
QString("%1 / %2 (%3x)") QMetaMethod metaMethod = sender()->metaObject()->method(senderSignalIndex());
.arg(Utils::createTimestamp(getProperty("time-pos").toInt()), if (metaMethod.name() == "positionChanged") {
totalDurationString, if (speed != lastSpeed) {
getProperty("speed").toString())); lastSpeed = speed.toDouble();
} else {
if (numTime == lastTime) {
return;
}
}
lastTime = numTime;
lastPositionString = Utils::createTimestamp(lastTime);
} else if (metaMethod.name() == "durationChanged") {
totalDurationString = Utils::createTimestamp(numTime);
}
QString durationString;
durationString += lastPositionString;
durationString += " / ";
durationString += totalDurationString;
if (lastSpeed != 1) {
durationString += " (" + speed.toString() + "x)";
}
emit durationStringChanged(durationString);
} }
void void
@ -496,13 +514,12 @@ MpvPlayerBackend::handle_mpv_event(mpv_event* event)
if (prop->format == MPV_FORMAT_DOUBLE) { if (prop->format == MPV_FORMAT_DOUBLE) {
double time = *(double*)prop->data; double time = *(double*)prop->data;
emit positionChanged(time); emit positionChanged(time);
Utils::ResetScreensaver();
} }
} else if (strcmp(prop->name, "duration") == 0) { } else if (strcmp(prop->name, "duration") == 0) {
if (prop->format == MPV_FORMAT_DOUBLE) { if (prop->format == MPV_FORMAT_DOUBLE) {
double time = *(double*)prop->data; double time = *(double*)prop->data;
totalDurationString = Utils::createTimestamp(time);
emit durationChanged(time); emit durationChanged(time);
Utils::ResetScreensaver();
} }
} else if (strcmp(prop->name, "mute") == 0 || } else if (strcmp(prop->name, "mute") == 0 ||
strcmp(prop->name, "volume") == 0) { strcmp(prop->name, "volume") == 0) {

View file

@ -27,7 +27,10 @@ class MpvPlayerBackend
mpv_handle* mpv; mpv_handle* mpv;
mpv_render_context* mpv_gl; mpv_render_context* mpv_gl;
bool onTop = false; bool onTop = false;
int lastTime = 0;
double lastSpeed = 0;
QString totalDurationString; QString totalDurationString;
QString lastPositionString;
friend class MpvRenderer; friend class MpvRenderer;
@ -77,7 +80,7 @@ signals:
private slots: private slots:
void doUpdate(); void doUpdate();
void on_mpv_events(); void on_mpv_events();
void updateDurationString(); void updateDurationString(int numTime);
private: private:
void handle_mpv_event(mpv_event* event); void handle_mpv_event(mpv_event* event);

View file

@ -1 +1,2 @@
<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48"><path d="M24 10V2L14 12l10 10v-8c6.6 0 12 5.4 12 12s-5.4 12-12 12-12-5.4-12-12H8c0 8.8 7.2 16 16 16s16-7.2 16-16-7.2-16-16-16zm-2.2 22h-1.7v-6.5l-2 .6v-1.4l3.5-1.3h.2V32zm8.5-3.5c0 .6-.1 1.2-.2 1.6s-.3.8-.6 1.1-.6.5-.9.7-.7.2-1.2.2-.8-.1-1.2-.2-.7-.4-.9-.7-.5-.7-.6-1.1-.2-1-.2-1.6V27c0-.6.1-1.2.2-1.6s.3-.8.6-1.1.6-.5.9-.7.7-.2 1.2-.2.8.1 1.2.2.7.4.9.7.5.7.6 1.1.2 1 .2 1.6v1.5zm-1.6-1.7c0-.4 0-.7-.1-1s-.1-.5-.2-.6-.2-.3-.4-.3-.3-.1-.5-.1-.4 0-.5.1-.3.2-.4.3-.2.4-.2.6-.1.6-.1 1v1.9c0 .4 0 .7.1 1s.1.5.2.6.2.3.4.3.3.1.5.1.4 0 .5-.1.3-.2.4-.3.2-.4.2-.6.1-.6.1-1v-1.9z"/></svg> <svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg" fill-rule="evenodd" clip-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="1.4" class="PlayerSeekBackwardButton-icon"><path d="M18.3 29A38 38 0 1 1 23 76.7a4 4 0 0 0-5.7 0l-2.8 2.8a4 4 0 0 0 0 5.7A50 50 0 1 0 8 22.8l-2-1.2a4 4 0 0 0-6 3.5v18.2a4 4 0 0 0 6 3.5L21.7 38a4 4 0 0 0 .2-7L18.3 29zM42 66a2 2 0 0 1-2 2h-4a2 2 0 0 1-2-2V40h-2a2 2 0 0 1-2-2v-4c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v32zm32 0a2 2 0 0 1-2 2H52a2 2 0 0 1-2-2V34c0-1.1.9-2 2-2h20a2 2 0 0 1 2 2v32zm-8-26h-8v20h8V40z"></path></svg>

Before

Width:  |  Height:  |  Size: 640 B

After

Width:  |  Height:  |  Size: 564 B

View file

@ -1 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48"><path d="M8 26c0 8.8 7.2 16 16 16s16-7.2 16-16h-4c0 6.6-5.4 12-12 12s-12-5.4-12-12 5.4-12 12-12v8l10-10L24 2v8c-8.8 0-16 7.2-16 16zm13.7 6H20v-6.5l-2 .6v-1.4l3.5-1.3h.2V32zm8.5-3.5c0 .6-.1 1.2-.2 1.6s-.3.8-.6 1.1-.6.5-.9.7-.7.2-1.2.2-.8-.1-1.2-.2-.7-.4-.9-.7-.5-.7-.6-1.1-.2-1-.2-1.6V27c0-.6.1-1.2.2-1.6s.3-.8.6-1.1.6-.5.9-.7.7-.2 1.2-.2.8.1 1.2.2.7.4.9.7.5.7.6 1.1.2 1 .2 1.6v1.5zm-1.7-1.7c0-.4 0-.7-.1-1s-.1-.5-.2-.6-.2-.3-.4-.3-.3-.1-.5-.1-.4 0-.5.1-.3.2-.4.3-.2.4-.2.6-.1.6-.1 1v1.9c0 .4 0 .7.1 1s.1.5.2.6.2.3.4.3.3.1.5.1.4 0 .5-.1.3-.2.4-.3.2-.4.2-.6.1-.6.1-1v-1.9z"/></svg> <svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg" fill-rule="evenodd" clip-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="1.4" class="PlayerSeekForwardButton-icon"><path d="M81.7 29A38 38 0 1 0 77 76.7a4 4 0 0 1 5.7 0l2.8 2.8a4 4 0 0 1 0 5.7A50 50 0 1 1 92 22.8l2-1.2a4 4 0 0 1 6 3.5v18.2a4 4 0 0 1-6 3.5L78.3 38a4 4 0 0 1-.2-7l3.7-2.1zM37 66a2 2 0 0 1-2 2h-4a2 2 0 0 1-2-2V40h-2a2 2 0 0 1-2-2v-4c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v32zm32 0a2 2 0 0 1-2 2H47a2 2 0 0 1-2-2V34c0-1.1.9-2 2-2h20a2 2 0 0 1 2 2v32zm-8-26h-8v20h8V40z"></path></svg>

Before

Width:  |  Height:  |  Size: 642 B

After

Width:  |  Height:  |  Size: 561 B