libvlc_media_player_get_full_chapter_descriptions only returns chapters when media player is playing
When using libvlc_media_player_get_full_chapter_descriptions, it only returns chapters when the media player is playing.
Parsing media first makes no difference here.
When the media player is stopped, the chapters are no longer available, even if the media player and media are not released.
Is this the expected behaviour?
This code demonstrates the issue:
#include <stdio.h>
#include <unistd.h>
#include "vlc.h"
static void dump_chapters(libvlc_media_player_t *p_mi, int i_title) {
libvlc_chapter_description_t **p_chapters;
int i_count = libvlc_media_player_get_full_chapter_descriptions(p_mi, i_title, &p_chapters);
if (i_count != -1) {
printf(" Number of chapters: %d\n", i_count);
for (int i = 0; i < i_count; i++) {
printf(" [%d] @ %05ld -> %s\n", i+1, p_chapters[i]->i_time_offset, p_chapters[i]->psz_name);
}
libvlc_chapter_descriptions_release(p_chapters, i_count);
} else {
printf(" No chapters\n");
}
printf("\n");
}
static void parsed_callback(const struct libvlc_event_t *p_event, void *p_data) {
int new_status = p_event->u.media_parsed_changed.new_status;
if (new_status == libvlc_media_parsed_status_done) {
printf("Parsed done\n");
dump_chapters((libvlc_media_player_t*) p_data, 0);
}
}
static void playing_callback(const struct libvlc_event_t *p_event, void *p_data) {
printf("Playing\n");
dump_chapters((libvlc_media_player_t*) p_data, 0);
}
static void stopped_callback(const struct libvlc_event_t *p_event, void *p_data) {
printf("Stopped\n");
dump_chapters((libvlc_media_player_t*) p_data, 0);
}
int main(char **argv, int argc) {
const char *args[] = {"--quiet"};
libvlc_instance_t *p_instance = libvlc_new(1, args);
libvlc_media_t *p_md = libvlc_media_new_path(p_instance, "./sample.mp4");
libvlc_media_player_t *p_mi = libvlc_media_player_new_from_media(p_md);
libvlc_event_manager_t *p_event_manager = libvlc_media_player_event_manager(p_mi);
libvlc_event_attach(p_event_manager, libvlc_MediaPlayerPlaying, playing_callback, p_mi);
libvlc_event_attach(p_event_manager, libvlc_MediaPlayerStopped, stopped_callback, p_mi);
libvlc_event_manager_t *p_media_event_manager = libvlc_media_event_manager(p_md);
libvlc_event_attach(p_media_event_manager, libvlc_MediaParsedChanged, parsed_callback, p_mi);
printf("Start of test\n\n");
libvlc_media_parse_with_options(p_md, libvlc_media_parse_local, 1000);
sleep(1);
printf("Before play\n");
dump_chapters(p_mi, 0);
libvlc_media_player_play(p_mi);
sleep(1);
libvlc_media_player_stop_async(p_mi);
sleep(1);
printf("End of test\n");
libvlc_media_release(p_md);
libvlc_media_player_release(p_mi);
libvlc_release(p_instance);
return 0;
}
The attached "sample.mp4" file is a short video file (just a black screen) with three chapters.
The output of this test program is consistently:
Start of test
Parsed done
No chapters
Parsed done
No chapters
Before play
No chapters
Playing
Number of chapters: 3
[1] @ 00001 -> The first chapter
[2] @ 01001 -> The second chapter
[3] @ 05001 -> The third chapter
Stopped
No chapters
End of test