[Backend+UI] Added backend settings and made some changes to MPV events.
This commit is contained in:
parent
13b4b53e9d
commit
975a548ef6
|
@ -21,8 +21,8 @@
|
|||
void
|
||||
wakeup(void* ctx)
|
||||
{
|
||||
QMetaObject::invokeMethod(
|
||||
(DirectMpvPlayerBackend*)ctx, "on_mpv_events", Qt::QueuedConnection);
|
||||
QCoreApplication::postEvent((DirectMpvPlayerBackend*)ctx,
|
||||
new QEvent(QEvent::User));
|
||||
}
|
||||
|
||||
static void*
|
||||
|
@ -99,8 +99,8 @@ DirectMpvPlayerBackend::DirectMpvPlayerBackend(QQuickItem* parent)
|
|||
mpv_observe_property(mpv, 0, "playback-abort", MPV_FORMAT_NONE);
|
||||
mpv_observe_property(mpv, 0, "chapter-list", MPV_FORMAT_NODE);
|
||||
mpv_observe_property(mpv, 0, "track-list", MPV_FORMAT_NODE);
|
||||
mpv_observe_property(mpv, 0, "chapter-list", MPV_FORMAT_NONE);
|
||||
mpv_observe_property(mpv, 0, "audio-device-list", MPV_FORMAT_NODE);
|
||||
mpv_observe_property(mpv, 0, "chapter-list", MPV_FORMAT_NODE);
|
||||
mpv_observe_property(mpv, 0, "audio-device-list", MPV_FORMAT_NONE);
|
||||
mpv_observe_property(mpv, 0, "playlist-pos", MPV_FORMAT_DOUBLE);
|
||||
mpv_observe_property(mpv, 0, "volume", MPV_FORMAT_NONE);
|
||||
mpv_observe_property(mpv, 0, "mute", MPV_FORMAT_NONE);
|
||||
|
@ -110,7 +110,7 @@ DirectMpvPlayerBackend::DirectMpvPlayerBackend(QQuickItem* parent)
|
|||
mpv_observe_property(mpv, 0, "time-pos", MPV_FORMAT_DOUBLE);
|
||||
mpv_observe_property(mpv, 0, "demuxer-cache-duration", MPV_FORMAT_DOUBLE);
|
||||
mpv_observe_property(mpv, 0, "pause", MPV_FORMAT_NONE);
|
||||
mpv_observe_property(mpv, 0, "playlist", MPV_FORMAT_NONE);
|
||||
mpv_observe_property(mpv, 0, "playlist", MPV_FORMAT_NODE);
|
||||
mpv_set_wakeup_callback(mpv, wakeup, this);
|
||||
|
||||
if (mpv_initialize(mpv) < 0)
|
||||
|
@ -449,6 +449,15 @@ DirectMpvPlayerBackend::toggleOnTop()
|
|||
Utils::AlwaysOnTop(window()->winId(), onTop);
|
||||
}
|
||||
|
||||
bool
|
||||
DirectMpvPlayerBackend::event(QEvent* event)
|
||||
{
|
||||
if (event->type() == QEvent::User) {
|
||||
on_mpv_events();
|
||||
}
|
||||
return QObject::event(event);
|
||||
}
|
||||
|
||||
void
|
||||
DirectMpvPlayerBackend::on_mpv_events()
|
||||
{
|
||||
|
@ -557,14 +566,17 @@ DirectMpvPlayerBackend::handle_mpv_event(mpv_event* event)
|
|||
} else {
|
||||
emit playStatusChanged(Enums::PlayStatus::Playing);
|
||||
}
|
||||
} else if (strcmp(prop->name, "tracks-menu") == 0) {
|
||||
emit tracksChanged(getProperty("tracks-menu").toList());
|
||||
} else if (strcmp(prop->name, "track-list") == 0) {
|
||||
mpv_node* nod = (mpv_node*)prop->data;
|
||||
emit tracksChanged(mpv::qt::node_to_variant(nod).toList());
|
||||
} else if (strcmp(prop->name, "audio-device-list") == 0) {
|
||||
emit audioDevicesChanged(getAudioDevices());
|
||||
} else if (strcmp(prop->name, "playlist") == 0) {
|
||||
emit playlistChanged(getProperty("playlist").toList());
|
||||
mpv_node* nod = (mpv_node*)prop->data;
|
||||
emit playlistChanged(mpv::qt::node_to_variant(nod).toList());
|
||||
} else if (strcmp(prop->name, "chapter-list") == 0) {
|
||||
emit chaptersChanged(getProperty("chapter-list").toList());
|
||||
mpv_node* nod = (mpv_node*)prop->data;
|
||||
emit chaptersChanged(mpv::qt::node_to_variant(nod).toList());
|
||||
}
|
||||
#ifdef DISCORD
|
||||
updateDiscord();
|
||||
|
|
|
@ -68,6 +68,7 @@ public slots:
|
|||
|
||||
// Just used for adding missing audio devices to list.
|
||||
QVariantMap getAudioDevices() const;
|
||||
bool event(QEvent* event);
|
||||
|
||||
signals:
|
||||
void onUpdate();
|
||||
|
|
|
@ -27,8 +27,7 @@ namespace {
|
|||
void
|
||||
wakeup(void* ctx)
|
||||
{
|
||||
QMetaObject::invokeMethod(
|
||||
(MpvPlayerBackend*)ctx, "on_mpv_events", Qt::QueuedConnection);
|
||||
QCoreApplication::postEvent((MpvPlayerBackend*)ctx, new QEvent(QEvent::User));
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -147,11 +146,11 @@ MpvPlayerBackend::MpvPlayerBackend(QQuickItem* parent)
|
|||
mpv_set_option_string(mpv, "config", "yes");
|
||||
// mpv_set_option_string(mpv, "sub-visibility", "no");
|
||||
mpv_observe_property(mpv, 0, "tracks-menu", MPV_FORMAT_NONE);
|
||||
mpv_observe_property(mpv, 0, "chapter-list", MPV_FORMAT_NONE);
|
||||
mpv_observe_property(mpv, 0, "chapter-list", MPV_FORMAT_NODE);
|
||||
mpv_observe_property(mpv, 0, "playback-abort", MPV_FORMAT_NONE);
|
||||
mpv_observe_property(mpv, 0, "chapter-list", MPV_FORMAT_NODE);
|
||||
mpv_observe_property(mpv, 0, "track-list", MPV_FORMAT_NODE);
|
||||
mpv_observe_property(mpv, 0, "audio-device-list", MPV_FORMAT_NODE);
|
||||
mpv_observe_property(mpv, 0, "audio-device-list", MPV_FORMAT_NONE);
|
||||
mpv_observe_property(mpv, 0, "playlist-pos", MPV_FORMAT_DOUBLE);
|
||||
mpv_observe_property(mpv, 0, "volume", MPV_FORMAT_NONE);
|
||||
mpv_observe_property(mpv, 0, "mute", MPV_FORMAT_NONE);
|
||||
|
@ -160,8 +159,8 @@ MpvPlayerBackend::MpvPlayerBackend(QQuickItem* parent)
|
|||
mpv_observe_property(mpv, 0, "sub-text", MPV_FORMAT_STRING);
|
||||
mpv_observe_property(mpv, 0, "time-pos", MPV_FORMAT_DOUBLE);
|
||||
mpv_observe_property(mpv, 0, "demuxer-cache-duration", MPV_FORMAT_DOUBLE);
|
||||
mpv_observe_property(mpv, 0, "pause", MPV_FORMAT_NONE);
|
||||
mpv_observe_property(mpv, 0, "playlist", MPV_FORMAT_NONE);
|
||||
mpv_observe_property(mpv, 0, "pause", MPV_FORMAT_DOUBLE);
|
||||
mpv_observe_property(mpv, 0, "playlist", MPV_FORMAT_NODE);
|
||||
mpv_set_wakeup_callback(mpv, wakeup, this);
|
||||
|
||||
if (mpv_initialize(mpv) < 0)
|
||||
|
@ -427,6 +426,15 @@ MpvPlayerBackend::toggleOnTop()
|
|||
Utils::AlwaysOnTop(window()->winId(), onTop);
|
||||
}
|
||||
|
||||
bool
|
||||
MpvPlayerBackend::event(QEvent* event)
|
||||
{
|
||||
if (event->type() == QEvent::User) {
|
||||
on_mpv_events();
|
||||
}
|
||||
return QObject::event(event);
|
||||
}
|
||||
|
||||
void
|
||||
MpvPlayerBackend::on_mpv_events()
|
||||
{
|
||||
|
@ -497,6 +505,7 @@ MpvPlayerBackend::handle_mpv_event(mpv_event* event)
|
|||
}
|
||||
} else if (strcmp(prop->name, "mute") == 0 ||
|
||||
strcmp(prop->name, "volume") == 0) {
|
||||
return;
|
||||
double volume = getProperty("volume").toDouble();
|
||||
bool mute = getProperty("mute").toBool();
|
||||
if (mute || volume == 0) {
|
||||
|
@ -530,19 +539,24 @@ MpvPlayerBackend::handle_mpv_event(mpv_event* event)
|
|||
emit playlistPositionChanged(pos);
|
||||
}
|
||||
} else if (strcmp(prop->name, "pause") == 0) {
|
||||
mpv_node* nod = (mpv_node*)prop->data;
|
||||
qDebug() << mpv::qt::node_to_variant(nod);
|
||||
if (getProperty("pause").toBool()) {
|
||||
emit playStatusChanged(Enums::PlayStatus::Paused);
|
||||
} else {
|
||||
emit playStatusChanged(Enums::PlayStatus::Playing);
|
||||
}
|
||||
} else if (strcmp(prop->name, "tracks-menu") == 0) {
|
||||
emit tracksChanged(getProperty("track-list").toList());
|
||||
} else if (strcmp(prop->name, "track-list") == 0) {
|
||||
mpv_node* nod = (mpv_node*)prop->data;
|
||||
emit tracksChanged(mpv::qt::node_to_variant(nod).toList());
|
||||
} else if (strcmp(prop->name, "audio-device-list") == 0) {
|
||||
emit audioDevicesChanged(getAudioDevices());
|
||||
} else if (strcmp(prop->name, "playlist") == 0) {
|
||||
emit playlistChanged(getProperty("playlist").toList());
|
||||
mpv_node* nod = (mpv_node*)prop->data;
|
||||
emit playlistChanged(mpv::qt::node_to_variant(nod).toList());
|
||||
} else if (strcmp(prop->name, "chapter-list") == 0) {
|
||||
emit chaptersChanged(getProperty("chapter-list").toList());
|
||||
mpv_node* nod = (mpv_node*)prop->data;
|
||||
emit chaptersChanged(mpv::qt::node_to_variant(nod).toList());
|
||||
}
|
||||
#ifdef DISCORD
|
||||
updateDiscord();
|
||||
|
|
|
@ -49,10 +49,13 @@ public slots:
|
|||
QVariant getProperty(const QString& name) const;
|
||||
// Just used for adding missing audio devices to list.
|
||||
QVariantMap getAudioDevices() const;
|
||||
bool event(QEvent* event);
|
||||
|
||||
signals:
|
||||
void onUpdate();
|
||||
void mpv_events();
|
||||
void onMpvEvent(mpv_event* event);
|
||||
|
||||
// All below required for Player API
|
||||
void playStatusChanged(const Enums::PlayStatus& status);
|
||||
void volumeStatusChanged(const Enums::VolumeStatus& status);
|
||||
|
|
11
src/main.cpp
11
src/main.cpp
|
@ -97,6 +97,17 @@ main(int argc, char* argv[])
|
|||
app.setOrganizationName("KittehPlayer");
|
||||
app.setOrganizationDomain("namedkitten.pw");
|
||||
app.setApplicationName("KittehPlayer");
|
||||
|
||||
QSettings settings;
|
||||
QString backendSetting = settings.value("Backend/backend", "mpv").toString();
|
||||
if (backendSetting == "mpv") {
|
||||
qDebug() << "Using MPV backend.";
|
||||
backend = Enums::Backends::MpvBackend;
|
||||
} else if (backendSetting == "direct-mpv") {
|
||||
qDebug() << "Using Direct MPV backend.";
|
||||
backend = Enums::Backends::DirectMpvBackend;
|
||||
}
|
||||
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
if (!qstrcmp(argv[i], "--update")) {
|
||||
Utils::updateAppImage();
|
||||
|
|
|
@ -20,6 +20,12 @@ Window {
|
|||
id: translate
|
||||
}
|
||||
|
||||
Settings {
|
||||
id: backendSettings
|
||||
category: "Backend"
|
||||
property string backend: "mpv"
|
||||
}
|
||||
|
||||
Settings {
|
||||
id: appearance
|
||||
category: "Appearance"
|
||||
|
|
|
@ -41,12 +41,20 @@ updateAppImage()
|
|||
qApp->exit();
|
||||
}
|
||||
|
||||
// https://www.youtube.com/watch?v=nXaxk27zwlk&feature=youtu.be&t=56m34s
|
||||
int
|
||||
fast_mod(const int input, const int ceil)
|
||||
{
|
||||
return input >= ceil ? input % ceil : input;
|
||||
}
|
||||
|
||||
QString
|
||||
createTimestamp(int seconds)
|
||||
{
|
||||
int h = floor(seconds / 3600);
|
||||
int m = floor(seconds % 3600 / 60);
|
||||
int s = floor(seconds % 3600 % 60);
|
||||
|
||||
int s = fast_mod(seconds, 60);
|
||||
int m = fast_mod(seconds, 3600) / 60;
|
||||
int h = fast_mod(seconds, 86400) / 3600;
|
||||
|
||||
if (h > 0) {
|
||||
return QString::asprintf("%02d:%02d:%02d", h, m, s);
|
||||
|
|
Loading…
Reference in a new issue