diff options
author | wm4 <wm4@nowhere> | 2014-09-15 18:38:42 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2014-09-15 18:38:42 +0200 |
commit | 930c61b64c58d5b951abeb5de143c00520b89eba (patch) | |
tree | 90760be7d2952a6894886d8787ec3eb7f1133b88 /DOCS | |
parent | ac2047e02e766abfad2f209160fb445937e2a919 (diff) | |
download | mpv-930c61b64c58d5b951abeb5de143c00520b89eba.tar.bz2 mpv-930c61b64c58d5b951abeb5de143c00520b89eba.tar.xz |
DOCS/client_api_examples: qtexample: resize to video size
This is pretty imperfect, but it's just a demo.
The main purpose is clarifying how and when to get the video size.
In theory, retrieving the properties this way has a race condition:
after reading dwidth, the video could resize again. But the worst that
can happen are mismatching dwidth/dheight values, and the
MPV_EVENT_VIDEO_RECONFIG event would be immediately received again,
which would fix the mismatch. You could read the full video-out-params
property to absolutely avoid it, but it's not worth the trouble.
Diffstat (limited to 'DOCS')
-rw-r--r-- | DOCS/client_api_examples/qtexample.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/DOCS/client_api_examples/qtexample.cpp b/DOCS/client_api_examples/qtexample.cpp index 354e5d9a34..39dc1fd1d4 100644 --- a/DOCS/client_api_examples/qtexample.cpp +++ b/DOCS/client_api_examples/qtexample.cpp @@ -45,6 +45,7 @@ MainWindow::MainWindow(QWidget *parent) : mpv_container = new QWidget(this); setCentralWidget(mpv_container); mpv_container->setAttribute(Qt::WA_NativeWindow); + // If you have a HWND, use: int64_t wid = (intptr_t)hwnd; int64_t wid = mpv_container->winId(); mpv_set_option(mpv, "wid", MPV_FORMAT_INT64, &wid); @@ -84,6 +85,26 @@ void MainWindow::handle_mpv_event(mpv_event *event) } break; } + case MPV_EVENT_VIDEO_RECONFIG: { + // Retrieve the new video size. + int64_t w, h; + if (mpv_get_property(mpv, "dwidth", MPV_FORMAT_INT64, &w) >= 0 && + mpv_get_property(mpv, "dheight", MPV_FORMAT_INT64, &h) >= 0 && + w > 0 && h > 0) + { + // Force Qt to resize the mpv window to video size. You probably + // want to do something more sophisticated here, because: + // A) it prevents the user from making the window smaller for no + // reason (I was unsure how to make Qt do the right thing) + // B) the MPV_EVENT_VIDEO_RECONFIG event doesn't necessarily imply + // a resize, and you should check yourself if the video + // dimensions really changed + // mpv itself will scale/letter box the video to the container size + // if the video doesn't fit. + mpv_container->setMinimumSize(w, h); + } + break; + } case MPV_EVENT_SHUTDOWN: { mpv_terminate_destroy(mpv); mpv = NULL; |