I'm using Visual Studio/C++. I've downloaded the LibVLC tarball, and the VLC program. I copied the DLLs (libvlc, libvlccore) into libvlc_bin. I copied libvlc.lib, and libvlccore.lib into libvlc_lib. Finally, I copied the contents of vlc-3.0.10.tar.xz/vlc-3.0.10/include to libvlc_include.
My project directory looks like:
- ConsoleApplication1
- ConsoleApplication1
- Debug
libvlc_bin
libvlc_include
libvlc_lib
plugins
...
ConsoleApplication1.sln - Debug
- ConsoleApplication1
I haven't figured out what to do with the bin directory yet. Things have moved around a bit, but I know it needs to be copied into the debug directory where the debug exe appears, so for the moment I've manually copied the DLLs to that directory.
With setup complete, and dlls copied to the debug directory, I followed the directions here:
https://wiki.videolan.org/LibVLC_Tutorial/#Windows
When I look at the code, the first issue is an error -- sleep() is undefined. I include Windows.h, and made a macro for it at line 6 (just in case it's used somewhere i can't see):
Code: Select all
#define sleep(x) Sleep(1000 * (x))
The full code is below:Exception thrown at 0x7AA6A6A9 (libvlc.dll) in ConsoleApplication1.exe: 0xC00000005: Access violation reading location 0x0000000C
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <vlc/vlc.h>
#include <Windows.h>
#define sleep(x) Sleep(1000 * (x))
int main(int argc, char* argv[])
{
libvlc_instance_t* inst;
libvlc_media_player_t* mp;
libvlc_media_t* m;
/* Load the VLC engine */
inst = libvlc_new(0, NULL);
/* Create a new item */
//m = libvlc_media_new_location(inst, "https://file-examples.com/wp-content/uploads/2018/04/file_example_MOV_480_700kB.mov");
m = libvlc_media_new_path (inst, "C:/Repos/test.mpg");
/* Create a media player playing environement */
mp = libvlc_media_player_new_from_media(m); // This is line 23
/* No need to keep the media now */
libvlc_media_release(m);
#if 0
/* This is a non working code that show how to hooks into a window,
* if we have a window around */
libvlc_media_player_set_xwindow(mp, xid);
/* or on windows */
libvlc_media_player_set_hwnd(mp, hwnd);
/* or on mac os */
libvlc_media_player_set_nsobject(mp, view);
#endif
/* play the media_player */
libvlc_media_player_play(mp);
sleep(10); /* Let it play a bit */
/* Stop playing */
libvlc_media_player_stop(mp);
/* Free the media_player */
libvlc_media_player_release(mp);
libvlc_release(inst);
return 0;
}
Any ideas? I feel like there's something simple I'm missing here.
Update
While playing around a bit more, I've come to realize that something is wrong with the files I'm using. I took the DLL and includes out of the official downloads, but I always get access violations. I found an older project online where someone gave simple examples using libVLC 2.x.x.x. I copied their lib, include, and dll files into the appropriate places and the example code I gave above now works.