Add duration and position to meatadata
This commit is contained in:
parent
d94fa07ec2
commit
e68aa6f457
@ -158,10 +158,22 @@ struct song_metadata dbusGetSong( DBusConnection *conn, const char *player ) {
|
||||
ret.file = strdup( meta_val );
|
||||
else if ( !strcmp( meta_name, "mpris:artUrl" ) )
|
||||
ret.art_uri = strdup( meta_val );
|
||||
} else if ( dbus_message_iter_get_arg_type( &variant ) ==
|
||||
DBUS_TYPE_INT64 ) {
|
||||
if ( !strcmp( meta_name, "mpris:length" ) ) {
|
||||
dbus_message_iter_get_basic( &variant, &ret.duration );
|
||||
}
|
||||
}
|
||||
} while ( dbus_message_iter_next( &dict ) );
|
||||
|
||||
dbus_message_unref( msg );
|
||||
|
||||
const char *params2[3] = { "org.mpris.MediaPlayer2.Player", "Position",
|
||||
NULL };
|
||||
dbusQuery( &args, &msg, conn, player, "/org/mpris/MediaPlayer2",
|
||||
"org.freedesktop.DBus.Properties", "Get", params2 );
|
||||
dbus_message_iter_recurse( &args, &variant );
|
||||
dbus_message_iter_get_basic( &variant, &ret.position );
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,8 @@ void printMeta( struct song_metadata *song ) {
|
||||
if ( song->art_uri != NULL ) {
|
||||
printf( "ART: %s\n", song->art_uri );
|
||||
}
|
||||
printf( "DURATION: %zu\n", song->duration );
|
||||
printf( "POSITION: %zu\n", song->position );
|
||||
}
|
||||
|
||||
void freeSong( struct song_metadata *song ) {
|
||||
|
@ -1,6 +1,8 @@
|
||||
#ifndef METADATA_H
|
||||
#define METADATA_H
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
struct song_metadata {
|
||||
const char *title;
|
||||
const char *artist;
|
||||
@ -8,6 +10,8 @@ struct song_metadata {
|
||||
const char *year;
|
||||
const char *file;
|
||||
const char *art_uri;
|
||||
size_t duration;
|
||||
size_t position;
|
||||
};
|
||||
|
||||
void printSong( struct song_metadata *song );
|
||||
|
@ -43,6 +43,14 @@ struct song_metadata mpdGetSong( struct mpd_connection *mpd_connection ) {
|
||||
ret.year = strdup( copy );
|
||||
|
||||
ret.file = strdup( mpd_song_get_uri( song ) );
|
||||
|
||||
struct mpd_status *status = mpd_run_status( mpd_connection );
|
||||
if ( status == NULL )
|
||||
goto endfree;
|
||||
ret.duration = mpd_status_get_total_time( status );
|
||||
ret.position = mpd_status_get_elapsed_time( status );
|
||||
|
||||
mpd_status_free( status );
|
||||
endfree:
|
||||
mpd_song_free( song );
|
||||
end:
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include <mpd/connection.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "metadata.h"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user