Using libVLC on Mac OS X + Qt5
Posted: 13 May 2016 11:57
I've been developing a cross-platform app which can be run on windows and mac. It is based on Qt 5.6 and libVLC v2.2.3. On Windows it works fine, but on Mac it doesn't display video, though the sound from the movie can be heard. I believe the issue is related to this function:
It seems winId() works very different in Qt4 and Qt5, therefore the code, which worked fine in Qt4, ceased to work in Qt5. I read about QMacCocoaViewContainer. Probably in Qt5 it must be used instead of a simple QWidget or QFrame, but I still haven't managed to make it work as QMacCocoaViewContainer crashes when setting a cocoa view instance:
Does anyone know how to fix this?
Code: Select all
libvlc_media_player_set_nsobject(vlcPlayer, (void*)videoWidget->winId()); // videoWidget is QFrame *
Code: Select all
QMacCocoaViewContainer container(0);
// Many Cocoa objects create temporary autorelease objects,
// so create a pool to catch them.
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
// Create the NSView, set it on the QCocoaViewContainer.
NSView *view = [[NSView alloc] init];
container.setCocoaView(view); // here it crashes saying EXC_BAD_ACCESS
// Release our reference, since our super class takes ownership and we
// don't need it anymore.
[view release];
// Clean up our pool as we no longer need it.
[pool release];
container.show();
....
libvlc_media_player_set_nsobject(vlcPlayer, (void*)container->cocoaView());