i'm writing media player in pure c , i'm using libvlc. i'm developing media library , i'm writing directory walker , media file parser. works pretty fine various metadata artists or albums, etc., libvlc_media_get_duration returns 0. tried , searched everywhere, can't make work. can me?
here code:
#include <stdlib.h> #include <stdio.h> #include <string.h> #include <vlc/vlc.h> #include <stdarg.h> #include <stdbool.h> #include <dirent.h> #include <sys/stat.h> void strcopy(char **dst, const char *src) { unsigned int size = strlen(src); *dst = (char *) realloc(*dst, sizeof(char) * (size + 1)); strncpy(*dst, src, size); *(*dst+size) = 0; } void strconcat(char **dst, int n, ...) { va_list args; unsigned int count = 0; // count va_start(args, n); (unsigned short = 0; < n; i++) count += strlen(va_arg(args, char*)); va_end(args); // allocate *dst = (char *) realloc(*dst, sizeof(char) * (count+1)); unsigned int cursor = 0; va_start(args, n); for(unsigned short = 0; < n; i++) { char *src = va_arg(args, char*); strncpy((*dst+cursor), src, strlen(src)); cursor += strlen(src); *(*dst+cursor) = 0; } va_end(args); } void /* process tags , add file database */ __db_add_file(libvlc_instance_t *inst, const char *url, bool compute_hash) { // create new media libvlc_media_t *media = libvlc_media_new_path(inst, url); libvlc_media_parse(media); if (libvlc_media_is_parsed(media)) { printf("%s\n", url); printf("%llu\n", libvlc_media_get_duration(media)); } libvlc_media_release(media); } void /* walker on directory */ __db_dir_walker(libvlc_instance_t *inst, const char *dir_url, bool compute_hash) { // build base path char *base_url = null; if (dir_url[strlen(dir_url)-1] != '/') strconcat(&base_url, 2, dir_url, "/"); else strcopy(&base_url, dir_url); // create necessary variables struct dirent *entry; dir *dir; struct stat fs; // try open dir if (!(dir = opendir(dir_url))) return; while (entry = readdir(dir)) { // strip parent entries if ((strcmp(".", entry->d_name) == 0) || (strcmp("..", entry->d_name) == 0)) continue; char *dir_full_path = null; strconcat(&dir_full_path, 2, base_url, entry->d_name); if (stat(dir_full_path, &fs) < 0) return; if (s_isdir(fs.st_mode)) { // process directory __db_dir_walker(inst, dir_full_path, compute_hash); } else { // process media file __db_add_file(inst, dir_full_path, compute_hash); } } // free memory closedir(dir); } void db_scan_directory(const char *dir_url, bool compute_hash) { // try open target dir if (!opendir(dir_url)) return; // preload vlc instance tag data retrieving libvlc_instance_t *inst = libvlc_new(0, null); // walk on directory __db_dir_walker(inst, dir_url, compute_hash); // free resources libvlc_release(inst); } int main () { db_scan_directory("/media/storage/music/blur/", false); return 0; }
thank you!
if there wants know answer on question too, here is:
you need play duration.
thanks jean-baptiste kempf videolan forums.
Comments
Post a Comment