VLC 4.0.0-dev
Loading...
Searching...
No Matches
LibVLC Documentation

Introduction

libVLC is an embeddable engine for 3rd party applications and frameworks.

It runs on the same platforms as VLC (and sometimes on more) and can provide playback, streaming and conversion of multimedia files and streams.

libVLC has numerous bindings for other languages, such as C++, Python, java, Objective-C and C#.

The generated documentation can be browsed from here.

License

libVLC is released under the LGPLv2 (or later) license. This allows embedding the engine in 3rd party applications, while letting them to be licensed under other licenses.

However, note that some plugins are under more restrictive licenses, such as GPLv3 (or later).

Example

4#include <stdio.h>
5#include <stdbool.h>
6#include <inttypes.h>
7#include <pthread.h>
8#include <vlc/vlc.h>
9
10struct cbs_context
11{
12 pthread_mutex_t lock; /* protect the following fields */
13 pthread_cond_t cond; /* signal on state or time change */
14 bool stopping; /* player is stopping */
15 bool stopped; /* player is stopped */
16 libvlc_time_t time_us; /* last reported time in microseconds */
17 bool time_changed; /* true if time_us has been updated since last check */
18};
19
20static void on_state_changed(void *opaque, libvlc_state_t state)
21{
22 struct cbs_context *ctx = opaque;
23
25 return;
26
27 pthread_mutex_lock(&ctx->lock);
29 ctx->stopping = true;
30 else
31 ctx->stopped = true;
32 pthread_cond_signal(&ctx->cond);
33 pthread_mutex_unlock(&ctx->lock);
34}
35
36static void on_position_changed(void *opaque, libvlc_time_t time, double pos)
37{
38 (void) pos;
39 struct cbs_context *ctx = opaque;
40
41 pthread_mutex_lock(&ctx->lock);
42 ctx->time_us = time;
43 ctx->time_changed = true;
44 pthread_cond_signal(&ctx->cond);
45 pthread_mutex_unlock(&ctx->lock);
46}
47
48int main(int argc, char* argv[])
49{
50 (void) argc; (void) argv;
51 libvlc_instance_t * inst;
54
55 struct cbs_context ctx = {
56 .lock = PTHREAD_MUTEX_INITIALIZER,
57 .cond = PTHREAD_COND_INITIALIZER,
58 .stopping = false,
59 .stopped = false,
60 .time_us = 0,
61 .time_changed = false,
62 };
63
64 /* Load the VLC engine */
65 inst = libvlc_new (0, NULL);
66
67 /* Create a new item */
68 m = libvlc_media_new_location("http://mycool.movie.com/test.mov");
69 //m = libvlc_media_new_path("/path/to/test.mov");
70
71 struct libvlc_media_player_cbs cbs = {
72 .version = 0,
73 .on_state_changed = on_state_changed,
74 .on_position_changed = on_position_changed,
75 };
76
77 /* Create a media player from the media */
78 mp = libvlc_media_player_new_from_media (inst, m, &cbs, &ctx);
79
80 /* No need to keep the media now */
82
83 /* play the media_player */
85
86 /* wait until either the position advances or the player is stopping. */
87 pthread_mutex_lock(&ctx.lock);
88 while (!ctx.stopping)
89 {
90 while (!ctx.stopping && !ctx.time_changed)
91 pthread_cond_wait(&ctx.cond, &ctx.lock);
92
93 if (ctx.time_changed)
94 {
95 ctx.time_changed = false;
96 libvlc_time_t microseconds = ctx.time_us;
97 int64_t seconds = microseconds / 1000000;
98 int64_t minutes = seconds / 60;
99 microseconds -= seconds * 1000000;
100 seconds -= minutes * 60;
101 pthread_mutex_unlock(&ctx.lock);
102 printf("Current time: %" PRId64 ":%" PRId64 ":%" PRId64 "\n",
103 minutes, seconds, microseconds);
104 pthread_mutex_lock(&ctx.lock);
105 }
106 }
107
108 /* Wait for the player to reach the Stopped state. */
109 while (!ctx.stopped)
110 pthread_cond_wait(&ctx.cond, &ctx.lock);
111 pthread_mutex_unlock(&ctx.lock);
112
113 /* Free the media_player */
115
116 libvlc_release (inst);
117
118 return 0;
119}