summaryrefslogtreecommitdiffstats
path: root/DOCS/client_api_examples
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-10-13 23:55:57 +0200
committerwm4 <wm4@nowhere>2014-10-13 23:55:57 +0200
commit2ad0be859243b5099767f82d60660e57df2cfbd5 (patch)
tree50c177f457538aeadcaeb050450db65cfdec7f95 /DOCS/client_api_examples
parent1c5dbdbfc20868ba6a305921f23746878ec8b5af (diff)
downloadmpv-2ad0be859243b5099767f82d60660e57df2cfbd5.tar.bz2
mpv-2ad0be859243b5099767f82d60660e57df2cfbd5.tar.xz
DOCS/client_api_examples: qtexample: stuff
Dump chapters and track list to the log for demo purposes. Compile in debug mode.
Diffstat (limited to 'DOCS/client_api_examples')
-rw-r--r--DOCS/client_api_examples/qtexample.cpp34
-rw-r--r--DOCS/client_api_examples/qtexample.h2
-rw-r--r--DOCS/client_api_examples/qtexample.pro2
3 files changed, 31 insertions, 7 deletions
diff --git a/DOCS/client_api_examples/qtexample.cpp b/DOCS/client_api_examples/qtexample.cpp
index b4b5934b57..d7d114fbd7 100644
--- a/DOCS/client_api_examples/qtexample.cpp
+++ b/DOCS/client_api_examples/qtexample.cpp
@@ -12,6 +12,9 @@
#include <QGridLayout>
#include <QApplication>
#include <QTextEdit>
+#include <QJsonDocument>
+
+#include <mpv/qthelper.hpp>
#include "qtexample.h"
@@ -74,9 +77,12 @@ MainWindow::MainWindow(QWidget *parent) :
// this property changes.
mpv_observe_property(mpv, 0, "time-pos", MPV_FORMAT_DOUBLE);
- // Request log messages with level verbose ("v") or higher.
+ mpv_observe_property(mpv, 0, "track-list", MPV_FORMAT_NODE);
+ mpv_observe_property(mpv, 0, "chapter-list", MPV_FORMAT_NODE);
+
+ // Request log messages with level "info" or higher.
// They are received as MPV_EVENT_LOG_MESSAGE.
- mpv_request_log_messages(mpv, "v");
+ mpv_request_log_messages(mpv, "info");
// From this point on, the wakeup function will be called. The callback
// can come from any thread, so we use the Qt QEvent mechanism to relay
@@ -103,6 +109,17 @@ void MainWindow::handle_mpv_event(mpv_event *event)
// was stopped.
statusBar()->showMessage("");
}
+ } else if (strcmp(prop->name, "chapter-list") == 0 ||
+ strcmp(prop->name, "track-list") == 0)
+ {
+ if (prop->format == MPV_FORMAT_NODE) {
+ QVariant v = mpv::qt::node_to_variant((mpv_node *)prop->data);
+ mpv::qt::node_builder x(v);
+ QVariant v2 = mpv::qt::node_to_variant(x.node());
+ QJsonDocument d = QJsonDocument::fromVariant(v);
+ append_log("Change property " + QString(prop->name) + ":\n");
+ append_log(d.toJson().data());
+ }
}
break;
}
@@ -128,10 +145,7 @@ void MainWindow::handle_mpv_event(mpv_event *event)
struct mpv_event_log_message *msg = (struct mpv_event_log_message *)event->data;
std::stringstream ss;
ss << "[" << msg->prefix << "] " << msg->level << ": " << msg->text;
- QTextCursor cursor = log->textCursor();
- cursor.movePosition(QTextCursor::End);
- cursor.insertText(QString::fromStdString(ss.str()));
- log->setTextCursor(cursor);
+ append_log(QString::fromStdString(ss.str()));
break;
}
case MPV_EVENT_SHUTDOWN: {
@@ -170,6 +184,14 @@ void MainWindow::on_file_open()
}
}
+void MainWindow::append_log(const QString &text)
+{
+ QTextCursor cursor = log->textCursor();
+ cursor.movePosition(QTextCursor::End);
+ cursor.insertText(text);
+ log->setTextCursor(cursor);
+}
+
MainWindow::~MainWindow()
{
if (mpv)
diff --git a/DOCS/client_api_examples/qtexample.h b/DOCS/client_api_examples/qtexample.h
index 8d5ef41143..672a818844 100644
--- a/DOCS/client_api_examples/qtexample.h
+++ b/DOCS/client_api_examples/qtexample.h
@@ -26,6 +26,8 @@ private:
mpv_handle *mpv;
QTextEdit *log;
+ void append_log(const QString &text);
+
void create_player();
void handle_mpv_event(mpv_event *event);
};
diff --git a/DOCS/client_api_examples/qtexample.pro b/DOCS/client_api_examples/qtexample.pro
index 03174b8778..84c34031d3 100644
--- a/DOCS/client_api_examples/qtexample.pro
+++ b/DOCS/client_api_examples/qtexample.pro
@@ -5,7 +5,7 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = qtexample
TEMPLATE = app
-CONFIG += link_pkgconfig
+CONFIG += link_pkgconfig debug
PKGCONFIG = mpv
SOURCES += qtexample.cpp