How to switch NSView on the fly?

This forum is about all development around libVLC.
RicoPL
New Cone
New Cone
Posts: 7
Joined: 07 Jan 2013 17:06
Operating System: Mac OS
Location: Poland

How to switch NSView on the fly?

Postby RicoPL » 08 Jan 2013 12:53

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?

Rémi Denis-Courmont
Developer
Developer
Posts: 15135
Joined: 07 Jun 2004 16:01
VLC version: master
Operating System: Linux
Contact:

Re: How to switch NSView on the fly?

Postby Rémi Denis-Courmont » 08 Jan 2013 13:44

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.
Rémi Denis-Courmont
https://www.remlab.net/
Private messages soliciting support will be systematically discarded

erwan10
Developer
Developer
Posts: 415
Joined: 02 Nov 2008 23:16

Re: How to switch NSView on the fly?

Postby erwan10 » 08 Jan 2013 15:40

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.

RicoPL
New Cone
New Cone
Posts: 7
Joined: 07 Jan 2013 17:06
Operating System: Mac OS
Location: Poland

Re: How to switch NSView on the fly?

Postby RicoPL » 25 Jan 2013 13:12

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


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 5 guests