I'm brand new to libvlc. I try in vain to open a simple m3u, but I can't.
The m3u opens with vlc, it's not the file.
I can also build and play a pls using "libvlc_media_list_add_media".
But not with an m3u, like in the vlc.
Please help me. Thanks in advance.
Code: Select all
/* VLC media player 3.0.16 Vetinari (revision 3.0.13-8-g41878ff4f2) */
/* cc example-playlist.c -lvlc -o example -I vlc/plugins */
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <syslog.h>
#include <string.h>
#include <unistd.h>
#include <vlc/vlc.h>
//#define STATIC_ITEMS
#define P_CHECK(V, A) do { \
if ((V) == NULL) { \
syslog(LOG_ERR, "%s at %s (%d): %s", #V, __FILE__, __LINE__, strerror(errno)); \
A; \
} \
} while (0);
void err()
{
printf(">>> ERROR: var is NULL!\n");
}
int main(int argc, char* argv[])
{
(void) argc; (void) argv;
libvlc_instance_t * inst = NULL;
libvlc_media_player_t *mp = NULL;
libvlc_media_list_player_t *mlp = NULL;
libvlc_media_t *m = NULL;
libvlc_media_list_t *ml = NULL;
/* Load the VLC engine */
static const char *const args[] = { "--verbose=2" /* full log */ };
inst = libvlc_new (sizeof(args) / sizeof(*args) , args);
/* Create a new item(s) */
m = libvlc_media_new_path (inst, "test.m3u");
//m = libvlc_media_new_location (inst, "file:///home/emanuel/C/libVlc/test.m3u");
P_CHECK(m, err);
printf(">>> libvlc_media_parse_with_options %d\n", libvlc_media_parse_with_options (m,
libvlc_media_parse_local | libvlc_media_parse_network,
10000));
printf(">>> libvlc_media_get_type %d\n", libvlc_media_get_type (m));
printf(">>> libvlc_media_get_state %d\n", libvlc_media_get_state (m));
printf(">>> libvlc_media_get_parsed_status %d\n", libvlc_media_get_parsed_status (m));
/* Create a new media_list */
ml = libvlc_media_subitems (m);
P_CHECK(ml, err);
/* No need to keep the media now */
libvlc_media_release (m);
if(libvlc_media_list_count (ml))
printf(">>> media_list has got %d items\n", libvlc_media_list_count (ml));
else
printf(">>> ERROR: emty media_list\n");
/* Create the media players */
mlp = libvlc_media_list_player_new (inst);
P_CHECK(mlp, err);
mp = libvlc_media_player_new (inst);
P_CHECK(mp, err);
libvlc_media_list_player_set_media_player (mlp, mp);
libvlc_media_list_player_set_media_list (mlp, ml);
libvlc_media_list_player_set_playback_mode (mlp, libvlc_playback_mode_default);
/* Start playing */
libvlc_media_list_player_play (mlp);
if(libvlc_media_list_player_is_playing (mlp))
printf(">>> libvlc_list_player is playing\n");
else
printf(">>> ERROR: libvlc_list_player is not playing\n");
sleep (30);
/* Stop playing */
libvlc_media_list_player_stop (mlp);
/* Free the media players */
libvlc_media_list_player_release (mlp);
libvlc_media_player_release (mp);
/* Free the media_list */
libvlc_media_list_release (ml);
/* Free the libvlc inst */
libvlc_release (inst);
return 0;
}