Using Video in QML – the hacky way
For my current QML project I am required to embed video “into” the QDeclarativeView. I think the proper way will be to use the Qt Multimedia package that comes with a QML VideoView but for this project the customer wanted to use a specific proprietary media player (I wish I could call names).
I started with creating a QWidget called VideoWidget and added three Q_INVOKABLE methods, one is setPos(x, y, w, h), setUrl(url) and play(), and bind one instance of that widget to the QML runtime. In the QML code I have one Rectangle {} where the video should be and us onWidthChanged, onHeightChanged, onXChanged, onYChanged to call the setPos on the QWidget. This mostly works but on start the x,y is not set properly but I am lucky as my video is not shown on start.
The next part is to actually host the video. In the first incarnation I was using the QAxContainer to host activeX content. Normally I use the testcon.exe, load the control, figure out which methods to invoke and then convert it to dynamicCalls. The only issue I faced was that ActiveX control just locked up on my copy of Windows7 but thanks to wine I could figure out what to do.
The only thing that was missing is to position the video on top of the QML content that appeared to be more difficult. The natural choice is to have the QDeclarativeView as parent to the VideoWidget, but that didn’t work, having a common QWidget as parent to the VideoWidget and QDeclarativeView also didn’t work. I had to resort to have two top level windows and trying to make them appear as one, so I had to handle QWidget::event(), use QWidget::setAttribute to have no taskbar for the video, etc.
Now this award winning closed source media player has quality and performance issues and I needed to try something else, sadly loading VLC in testcon.exe does not work properly, as it refuses any dynamic call to it, so in the end I am using Phonon for the video playback. The great thing about that solution is I can remove the hack with two top level windows and have a common QWidget as parent, and in the future I might be able to embed the videowidget into the QGraphicsScene of QML.
The bad part is DirectShow which doesn’t handle rtsp/mms and I am failing to find a ASX stream which works over HTTP. The best I can find is the flumotion demo site but that doesn’t offer a standalone URL I can throw to my player.