Page 1 of 1

How to switch NSView on the fly?

Posted: 08 Jan 2013 12:53
by RicoPL
I'm on the forum from two days and it's my second topic already... but hey, this is the place to get help :) ...and I really need it.

Another problem that I have is switching NSView while playing a stream.
I'm writing a crossplatform app but below I placed MacOS version of code. I assume that solution for this OS will be portable so I can use it on other systems.

The issue is that I'm using Phonon VideoWidget (Qt4) because it has build in fullscreen functionality ...but when I call "enterFullScreen" function the widget's "winId" is changed and vlc media player has still assigned the old one "winId". After entering a fullscreen mode I see only black background of Phonon's VideoWidget.

Second use of "libvlc_media_player_set_nsobject" function is useless without stopping media player. The code below shows my temporary solution but it uses stop/assign new nsobject/play concept and it costs extra time for new stream connection.

Code: Select all

// Constructor of the window const char * const vlc_args[] = { "-I", "dummy", "--ignore-config", "--extraintf=logger", "--verbose=2", "--no-video-title-show" }; inst = libvlc_new (sizeof(vlc_args) / sizeof(vlc_args[0]), vlc_args); m = libvlc_media_new_path (inst, "http://path.to/asf/stream/source"); mp = libvlc_media_player_new_from_media (m); widget = new Phonon::VideoWidget(this); ... // Play button libvlc_media_player_set_nsobject (mp, (void *) widget->winId()); libvlc_media_player_play(mp); ... // Fullscreen button libvlc_media_player_stop(mp); widget->enterFullScreen(); libvlc_media_player_set_nsobject (mp, (void *) widget->winId()); libvlc_media_player_play(mp);
Does anyone know the way to switch object for video rendering without stopping the media player?

Re: How to switch NSView on the fly?

Posted: 08 Jan 2013 13:44
by RĂ©mi Denis-Courmont
There is fundamentally no way to change window while playing. It is the application's responsibility to ensure that the window remains valid and its ID constant. Indeed, some output methods would crash or abort (e.g. OpenGL/GLX) if it were not the case.

Re: How to switch NSView on the fly?

Posted: 08 Jan 2013 15:40
by erwan10
Actually, the solution is at the application level. The winid you pass to libvlc cannot be changed while playing, but reparenting this winid to another visual object can be done on the fly whatever the OS. The only issue is that you may need to use platform dependent features of Qt4.

Re: How to switch NSView on the fly?

Posted: 25 Jan 2013 13:12
by RicoPL
These is the solution that I came up with, using tips from erwan10 and Remi:

Code: Select all

// Constructor of the window const char * const vlc_args[] = { "-I", "dummy", "--ignore-config", "--extraintf=logger", "--verbose=2", "--no-video-title-show" }; inst = libvlc_new (sizeof(vlc_args) / sizeof(vlc_args[0]), vlc_args); m = libvlc_media_new_path (inst, "http://path.to/asf/stream/source"); mp = libvlc_media_player_new_from_media (m); mainWgt = new QWidget(this); ui->verticalLayout->addWidget(mainWgt); videoWidget = new Phonon::VideoWidget(mainWgt); ... // play/start function #if defined(Q_OS_WIN) libvlc_media_player_set_hwnd (mp, (void *) videoWidget->winId()); #elif defined(Q_OS_MAC) libvlc_media_player_set_nsobject (mp, (void *) videoWidget->winId()); #else //Linux libvlc_media_player_set_xwindow (mp, (void *) videoWidget->winId()); #endif libvlc_media_player_play(mp); ... // reparenting function newWindow = new QDialog(); newWindow->show(); mainWgt->setParent(newWindow); mainWgt->show();
By far i've tested it on Mac OS only, but it works just great. Hope this helps someone else.

Yet another problem that I have is playing set of jpeg images as a video.
For anyone who would be willing to give me some tips, here is the topic:
viewtopic.php?f=32&t=107936