[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
|
void
|
||||||
wakeup(void* ctx)
|
wakeup(void* ctx)
|
||||||
{
|
{
|
||||||
QMetaObject::invokeMethod(
|
QCoreApplication::postEvent((DirectMpvPlayerBackend*)ctx,
|
||||||
(DirectMpvPlayerBackend*)ctx, "on_mpv_events", Qt::QueuedConnection);
|
new QEvent(QEvent::User));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void*
|
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, "playback-abort", MPV_FORMAT_NONE);
|
||||||
mpv_observe_property(mpv, 0, "chapter-list", MPV_FORMAT_NODE);
|
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, "track-list", MPV_FORMAT_NODE);
|
||||||
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, "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, "playlist-pos", MPV_FORMAT_DOUBLE);
|
||||||
mpv_observe_property(mpv, 0, "volume", MPV_FORMAT_NONE);
|
mpv_observe_property(mpv, 0, "volume", MPV_FORMAT_NONE);
|
||||||
mpv_observe_property(mpv, 0, "mute", 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, "time-pos", MPV_FORMAT_DOUBLE);
|
||||||
mpv_observe_property(mpv, 0, "demuxer-cache-duration", 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, "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);
|
mpv_set_wakeup_callback(mpv, wakeup, this);
|
||||||
|
|
||||||
if (mpv_initialize(mpv) < 0)
|
if (mpv_initialize(mpv) < 0)
|
||||||
|
@ -449,6 +449,15 @@ DirectMpvPlayerBackend::toggleOnTop()
|
||||||
Utils::AlwaysOnTop(window()->winId(), onTop);
|
Utils::AlwaysOnTop(window()->winId(), onTop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
DirectMpvPlayerBackend::event(QEvent* event)
|
||||||
|
{
|
||||||
|
if (event->type() == QEvent::User) {
|
||||||
|
on_mpv_events();
|
||||||
|
}
|
||||||
|
return QObject::event(event);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
DirectMpvPlayerBackend::on_mpv_events()
|
DirectMpvPlayerBackend::on_mpv_events()
|
||||||
{
|
{
|
||||||
|
@ -557,14 +566,17 @@ DirectMpvPlayerBackend::handle_mpv_event(mpv_event* event)
|
||||||
} else {
|
} else {
|
||||||
emit playStatusChanged(Enums::PlayStatus::Playing);
|
emit playStatusChanged(Enums::PlayStatus::Playing);
|
||||||
}
|
}
|
||||||
} else if (strcmp(prop->name, "tracks-menu") == 0) {
|
} else if (strcmp(prop->name, "track-list") == 0) {
|
||||||
emit tracksChanged(getProperty("tracks-menu").toList());
|
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) {
|
} else if (strcmp(prop->name, "audio-device-list") == 0) {
|
||||||
emit audioDevicesChanged(getAudioDevices());
|
emit audioDevicesChanged(getAudioDevices());
|
||||||
} else if (strcmp(prop->name, "playlist") == 0) {
|
} 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) {
|
} 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
|
#ifdef DISCORD
|
||||||
updateDiscord();
|
updateDiscord();
|
||||||
|
|
|
@ -68,6 +68,7 @@ public slots:
|
||||||
|
|
||||||
// Just used for adding missing audio devices to list.
|
// Just used for adding missing audio devices to list.
|
||||||
QVariantMap getAudioDevices() const;
|
QVariantMap getAudioDevices() const;
|
||||||
|
bool event(QEvent* event);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void onUpdate();
|
void onUpdate();
|
||||||
|
|
|
@ -27,8 +27,7 @@ namespace {
|
||||||
void
|
void
|
||||||
wakeup(void* ctx)
|
wakeup(void* ctx)
|
||||||
{
|
{
|
||||||
QMetaObject::invokeMethod(
|
QCoreApplication::postEvent((MpvPlayerBackend*)ctx, new QEvent(QEvent::User));
|
||||||
(MpvPlayerBackend*)ctx, "on_mpv_events", Qt::QueuedConnection);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -147,11 +146,11 @@ MpvPlayerBackend::MpvPlayerBackend(QQuickItem* parent)
|
||||||
mpv_set_option_string(mpv, "config", "yes");
|
mpv_set_option_string(mpv, "config", "yes");
|
||||||
// mpv_set_option_string(mpv, "sub-visibility", "no");
|
// mpv_set_option_string(mpv, "sub-visibility", "no");
|
||||||
mpv_observe_property(mpv, 0, "tracks-menu", MPV_FORMAT_NONE);
|
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, "playback-abort", MPV_FORMAT_NONE);
|
||||||
mpv_observe_property(mpv, 0, "chapter-list", MPV_FORMAT_NODE);
|
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, "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, "playlist-pos", MPV_FORMAT_DOUBLE);
|
||||||
mpv_observe_property(mpv, 0, "volume", MPV_FORMAT_NONE);
|
mpv_observe_property(mpv, 0, "volume", MPV_FORMAT_NONE);
|
||||||
mpv_observe_property(mpv, 0, "mute", 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, "sub-text", MPV_FORMAT_STRING);
|
||||||
mpv_observe_property(mpv, 0, "time-pos", MPV_FORMAT_DOUBLE);
|
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, "demuxer-cache-duration", MPV_FORMAT_DOUBLE);
|
||||||
mpv_observe_property(mpv, 0, "pause", MPV_FORMAT_NONE);
|
mpv_observe_property(mpv, 0, "pause", MPV_FORMAT_DOUBLE);
|
||||||
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);
|
mpv_set_wakeup_callback(mpv, wakeup, this);
|
||||||
|
|
||||||
if (mpv_initialize(mpv) < 0)
|
if (mpv_initialize(mpv) < 0)
|
||||||
|
@ -427,6 +426,15 @@ MpvPlayerBackend::toggleOnTop()
|
||||||
Utils::AlwaysOnTop(window()->winId(), onTop);
|
Utils::AlwaysOnTop(window()->winId(), onTop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
MpvPlayerBackend::event(QEvent* event)
|
||||||
|
{
|
||||||
|
if (event->type() == QEvent::User) {
|
||||||
|
on_mpv_events();
|
||||||
|
}
|
||||||
|
return QObject::event(event);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
MpvPlayerBackend::on_mpv_events()
|
MpvPlayerBackend::on_mpv_events()
|
||||||
{
|
{
|
||||||
|
@ -497,6 +505,7 @@ MpvPlayerBackend::handle_mpv_event(mpv_event* event)
|
||||||
}
|
}
|
||||||
} else if (strcmp(prop->name, "mute") == 0 ||
|
} else if (strcmp(prop->name, "mute") == 0 ||
|
||||||
strcmp(prop->name, "volume") == 0) {
|
strcmp(prop->name, "volume") == 0) {
|
||||||
|
return;
|
||||||
double volume = getProperty("volume").toDouble();
|
double volume = getProperty("volume").toDouble();
|
||||||
bool mute = getProperty("mute").toBool();
|
bool mute = getProperty("mute").toBool();
|
||||||
if (mute || volume == 0) {
|
if (mute || volume == 0) {
|
||||||
|
@ -530,19 +539,24 @@ MpvPlayerBackend::handle_mpv_event(mpv_event* event)
|
||||||
emit playlistPositionChanged(pos);
|
emit playlistPositionChanged(pos);
|
||||||
}
|
}
|
||||||
} else if (strcmp(prop->name, "pause") == 0) {
|
} 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()) {
|
if (getProperty("pause").toBool()) {
|
||||||
emit playStatusChanged(Enums::PlayStatus::Paused);
|
emit playStatusChanged(Enums::PlayStatus::Paused);
|
||||||
} else {
|
} else {
|
||||||
emit playStatusChanged(Enums::PlayStatus::Playing);
|
emit playStatusChanged(Enums::PlayStatus::Playing);
|
||||||
}
|
}
|
||||||
} else if (strcmp(prop->name, "tracks-menu") == 0) {
|
} else if (strcmp(prop->name, "track-list") == 0) {
|
||||||
emit tracksChanged(getProperty("track-list").toList());
|
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) {
|
} else if (strcmp(prop->name, "audio-device-list") == 0) {
|
||||||
emit audioDevicesChanged(getAudioDevices());
|
emit audioDevicesChanged(getAudioDevices());
|
||||||
} else if (strcmp(prop->name, "playlist") == 0) {
|
} 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) {
|
} 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
|
#ifdef DISCORD
|
||||||
updateDiscord();
|
updateDiscord();
|
||||||
|
|
|
@ -49,10 +49,13 @@ public slots:
|
||||||
QVariant getProperty(const QString& name) const;
|
QVariant getProperty(const QString& name) const;
|
||||||
// Just used for adding missing audio devices to list.
|
// Just used for adding missing audio devices to list.
|
||||||
QVariantMap getAudioDevices() const;
|
QVariantMap getAudioDevices() const;
|
||||||
|
bool event(QEvent* event);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void onUpdate();
|
void onUpdate();
|
||||||
void mpv_events();
|
void mpv_events();
|
||||||
|
void onMpvEvent(mpv_event* event);
|
||||||
|
|
||||||
// All below required for Player API
|
// All below required for Player API
|
||||||
void playStatusChanged(const Enums::PlayStatus& status);
|
void playStatusChanged(const Enums::PlayStatus& status);
|
||||||
void volumeStatusChanged(const Enums::VolumeStatus& 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.setOrganizationName("KittehPlayer");
|
||||||
app.setOrganizationDomain("namedkitten.pw");
|
app.setOrganizationDomain("namedkitten.pw");
|
||||||
app.setApplicationName("KittehPlayer");
|
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) {
|
for (int i = 1; i < argc; ++i) {
|
||||||
if (!qstrcmp(argv[i], "--update")) {
|
if (!qstrcmp(argv[i], "--update")) {
|
||||||
Utils::updateAppImage();
|
Utils::updateAppImage();
|
||||||
|
|
|
@ -20,6 +20,12 @@ Window {
|
||||||
id: translate
|
id: translate
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Settings {
|
||||||
|
id: backendSettings
|
||||||
|
category: "Backend"
|
||||||
|
property string backend: "mpv"
|
||||||
|
}
|
||||||
|
|
||||||
Settings {
|
Settings {
|
||||||
id: appearance
|
id: appearance
|
||||||
category: "Appearance"
|
category: "Appearance"
|
||||||
|
|
|
@ -41,12 +41,20 @@ updateAppImage()
|
||||||
qApp->exit();
|
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
|
QString
|
||||||
createTimestamp(int seconds)
|
createTimestamp(int seconds)
|
||||||
{
|
{
|
||||||
int h = floor(seconds / 3600);
|
|
||||||
int m = floor(seconds % 3600 / 60);
|
int s = fast_mod(seconds, 60);
|
||||||
int s = floor(seconds % 3600 % 60);
|
int m = fast_mod(seconds, 3600) / 60;
|
||||||
|
int h = fast_mod(seconds, 86400) / 3600;
|
||||||
|
|
||||||
if (h > 0) {
|
if (h > 0) {
|
||||||
return QString::asprintf("%02d:%02d:%02d", h, m, s);
|
return QString::asprintf("%02d:%02d:%02d", h, m, s);
|
||||||
|
|
Loading…
Reference in a new issue