Player controls

This commit is contained in:
zvon 2020-05-29 20:36:54 +02:00
parent e9b63f5727
commit 53a2e60d87
2 changed files with 38 additions and 1 deletions

View File

@ -147,7 +147,7 @@ struct song_metadata dbusGetSong( DBusConnection *conn, const char *player ) {
dbus_message_iter_recurse( &variant, &artists ); dbus_message_iter_recurse( &variant, &artists );
dbus_message_iter_get_basic( &artists, &meta_val ); dbus_message_iter_get_basic( &artists, &meta_val );
ret.artist = strdup( meta_val ); ret.artist = strdup( meta_val );
} else { } else if ( dbus_message_iter_get_arg_type( &variant ) == DBUS_TYPE_STRING ) {
dbus_message_iter_get_basic( &variant, &meta_val ); dbus_message_iter_get_basic( &variant, &meta_val );
if ( !strcmp( meta_name, "xesam:title" ) ) if ( !strcmp( meta_name, "xesam:title" ) )
ret.title = strdup( meta_val ); ret.title = strdup( meta_val );

37
main.c
View File

@ -10,6 +10,9 @@
#define SONG_FLAG 0x0001 #define SONG_FLAG 0x0001
#define META_FLAG 0x0002 #define META_FLAG 0x0002
#define RUNNING_FLAG 0x0004 #define RUNNING_FLAG 0x0004
#define NEXT_FLAG 0x0008
#define PREV_FLAG 0x0010
#define PLAY_FLAG 0x0020
#define MPD_FLAG 0x0001 #define MPD_FLAG 0x0001
#define DBUS_FLAG 0x0002 #define DBUS_FLAG 0x0002
@ -23,6 +26,12 @@ void parseCommandLine( int argc, char **argv, size_t *requests,
*requests |= META_FLAG; *requests |= META_FLAG;
else if ( !strcmp( argv[i], "status" ) ) else if ( !strcmp( argv[i], "status" ) )
*requests |= RUNNING_FLAG; *requests |= RUNNING_FLAG;
else if ( !strcmp( argv[i], "next" ) )
*requests |= NEXT_FLAG;
else if ( !strcmp( argv[i], "prev" ) || !strcmp( argv[i], "previous" ) )
*requests |= PREV_FLAG;
else if ( !strcmp( argv[i], "play" ) || !strcmp( argv[i], "pause" ) )
*requests |= PLAY_FLAG;
else if ( !strcmp( argv[i], "mpd" ) ) else if ( !strcmp( argv[i], "mpd" ) )
*sources |= MPD_FLAG; *sources |= MPD_FLAG;
else if ( !strcmp( argv[i], "dbus" ) ) else if ( !strcmp( argv[i], "dbus" ) )
@ -82,6 +91,34 @@ int main( int argc, char **argv ) {
} }
} }
if( requests & NEXT_FLAG ) {
if( sources & MPD_FLAG )
mpdNext( mpd_connection );
if( sources & DBUS_FLAG ) {
for( char **player = dbus_players; *player; ++player ) {
dbusNext( dbus_connection, *player );
}
}
}
if( requests & PREV_FLAG ) {
if( sources & MPD_FLAG )
mpdPrev( mpd_connection );
if( sources & DBUS_FLAG ) {
for( char **player = dbus_players; *player; ++player ) {
dbusPrev( dbus_connection, *player );
}
}
}
if( requests & PLAY_FLAG ) {
if( sources & MPD_FLAG )
mpdPlayPause( mpd_connection );
if( sources & DBUS_FLAG ) {
for( char **player = dbus_players; *player; ++player ) {
dbusPlayPause( dbus_connection, *player );
}
}
}
free( dbus_players ); free( dbus_players );
dbusDisconnect( dbus_connection ); dbusDisconnect( dbus_connection );
mpdDisconnect( mpd_connection ); mpdDisconnect( mpd_connection );