Page 1 of 1

mpc play seeks to 0 when already playing

Posted: April 2nd, 2014, 4:04 am
by emeres
This adds a feature to mpc of using 'mpc play' to restart a song (seek to 0s) when already playing. Patched against mpc version: 0.26 (release-0.25-3-gffcbf13) and tested with Music Player Daemon 0.19~git (release-0.18.9-941-g74a05a7). Struct put before first 'if', should make the second one unnecessary.

Code: Select all

--- src/command.c	2014-04-02 05:31:59.604298122 +0200
+++ src/command.c	2014-04-02 05:34:24.435358877 +0200
@@ -310,9 +310,13 @@
 int cmd_play ( int argc, char ** argv, struct mpd_connection *conn )
 {
 	int song;
-
-	if(0==argc) song = -1;
-	else {
+	struct mpd_status *status = getStatus(conn);
+	
+	if (0==argc) { song = -1;
+		if (mpd_status_get_state(status) == MPD_STATE_PLAY) {
+			if (!mpd_run_seek_id(conn, mpd_status_get_song_id(status), 0))
+				printErrorAndExit(conn); }
+	} else {
 		for (int i = 0; i < argc - 1; ++i)
 			printf("skipping: %s\n",argv[i]);