Skip to content

Instantly share code, notes, and snippets.

@kassane
Last active March 25, 2023 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kassane/f5a69286bd37655f7c71822c8c886f0a to your computer and use it in GitHub Desktop.
Save kassane/f5a69286bd37655f7c71822c8c886f0a to your computer and use it in GitHub Desktop.
libVLC simple example
#include <stdio.h>
#include <stdlib.h>
#include <vlc/vlc.h>
#if defined(_WIN32) || defined(_WIN64)
#include <Windows.h>
#else
#include <unistd.h>
#endif
int main(int argc, char **argv)
{
libvlc_instance_t *inst;
libvlc_media_player_t *mp;
libvlc_media_t *m;
// load the vlc engine (no libVLC log)
// inst = libvlc_new(0, NULL);
const char *const verbosity_args[] = { "--verbose", "2" }; //log level 2
// load the vlc engine
inst = libvlc_new(argc, verbosity_args);
// create a new item
m = libvlc_media_new_path(inst, argv[1]);
// m = libvlc_media_new_location (inst, "https://www.freedesktop.org/software/gstreamer-sdk/data/media/sintel_trailer-480p.webm");
// create a media play playing environment
mp = libvlc_media_player_new_from_media(m);
// no need to keep the media now
libvlc_media_release(m);
// play the media_player
libvlc_media_player_play(mp);
#if defined(_WIN32) || defined(_WIN64)
Sleep(50);
#else
sleep(50);
#endif
// stop playing
libvlc_media_player_stop(mp);
// free the media_player
libvlc_media_player_release(mp);
libvlc_release(inst);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment