问题
I am using Qt4.8 Windows version to develope an application to stream video using libvlc 2.2.1. When I use libvlc_media_player_set_hwnd()
to render the video on my QWidget, its rather creating a separate window to display the video.
libvlc_media_player_set_hwnd(m_player, (void*)videoWidget->winId());
I have tried all versions of libvlc and all the examples related to libvlc with Qt. Also followed the steps given in https://wiki.videolan.org/LibVLC_SampleCode_Qt/
But I am not sure if I m missing anything.
It looks like as if libvlc_media_player_set_hwnd()
is not able to take the QWidget WinId and creating its own window. However the value of (void*)videoWidget->winId()
seems to be a valid one. (I got the value as 0x65).
Please let me know if I am missing anything.
回答1:
You need to make sure you are configuring your VLC instance correctly first, so that it uses the dummy interface, for example:
/* Load the VLC engine */
std::vector<const char*> options;
options.push_back("--intf=dummy");
return libvlc_new(int(options.size()), options.data());
Also, are you sure you are passing the handle to the correct widget to render on? Also, make sure to set some size on the parent widget, otherwise you may not see anything render at all. Finally, check what media options you are setting to your media player instance, you may be inadvertently telling it to render to generated window.
I've been able to get VLC to work in my own Qt application using the following example as a starting point, even though it is for VLC 1.X:
LibVLC SampleCode Qt - VideoLAN Wiki
来源:https://stackoverflow.com/questions/30320657/libvlc-media-player-set-hwnd-doesnt-work-with-qwidget-handle