Hi guys, I am really new to libvlc. So the question must be dumb but I am stuck here.
Basically I followed the tutorial and was able to play some video clips. Now I want to attach vlc video to a hWnd. I am able to do this with GetDesktopWindow() and the video plays well. However, it only plays on my primary screen. if I create a hWnd (in InitInstance(...)) and use Libvlc_media_player_set_hwnd (), I can't see anything and the window just hang. I don't know what I did wrong. Can anyone help? Thanks very much.
I am sorry if this is the wrong place for such post.
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
hInst = hInstance; // Store instance handle in our global variable
hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
if (!hWnd)
{
return FALSE;
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
if (initLib(L"libvlc.dll") == EXITO)
{
player(hWnd);
}
return TRUE;
}
void player(HWND hWnd)
{
const char * const vlc_args[] = {
"-I", "dummy", /* Don't use any interface */
"--ignore-config", /* Don't use VLC's config */
"--plugin-path=C:\\...\\plugins"};
libvlc_exception_t ex;
libvlc_instance_t * inst;
libvlc_media_player_t *mp;
libvlc_media_t *m;
Libvlc_exception_init (&ex);
raise (&ex);
/* init vlc modules, should be done only once */
inst = Libvlc_new (sizeof(vlc_args) / sizeof(vlc_args[0]), vlc_args, &ex);
raise (&ex);
/* Create a new item */
m = Libvlc_media_new (inst, "c:\\Program Files\\QuickTime\\Sample.mov", &ex);
raise (&ex);
/* Create a media player playing environement */
mp = Libvlc_media_player_new_from_media (m, &ex);
raise (&ex);
/* No need to keep the media now */
Libvlc_media_release (m);
//HWND hWnd_0 = GetDesktopWindow(); This would work, the video would play on my primary monitor full screen
HWND hWnd_0 = hWnd;
if ( hWnd_0!=NULL )
{
libvlc_drawable_t drawable =(libvlc_drawable_t) hWnd_0;
Libvlc_media_player_set_hwnd (mp, drawable, &ex);
raise (&ex);
}
/* play the media_player */
Libvlc_media_player_play (mp, &ex);
raise (&ex);
Sleep (5000); /* Let it play a bit */
/* Stop playing */
Libvlc_media_player_stop (mp, &ex);
raise (&ex);
/* Free the media_player */
Libvlc_media_player_release (mp);
Libvlc_release (inst);
}