diff --git a/app/src/main/java/com/kabouzeid/gramophone/service/MediaButtonIntentReceiver.java b/app/src/main/java/com/kabouzeid/gramophone/service/MediaButtonIntentReceiver.java index 0bab58682..7bf48d773 100644 --- a/app/src/main/java/com/kabouzeid/gramophone/service/MediaButtonIntentReceiver.java +++ b/app/src/main/java/com/kabouzeid/gramophone/service/MediaButtonIntentReceiver.java @@ -17,7 +17,6 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; -import android.os.Build; import android.os.Handler; import android.os.Message; import android.os.PowerManager; @@ -66,7 +65,7 @@ public void handleMessage(final Message msg) { command = MusicService.ACTION_SKIP; break; case 3: - command = MusicService.ACTION_REWIND; + command = MusicService.ACTION_PREVIOUS; break; default: command = null; @@ -118,7 +117,7 @@ public static boolean handleIntent(final Context context, final Intent intent) { command = MusicService.ACTION_SKIP; break; case KeyEvent.KEYCODE_MEDIA_PREVIOUS: - command = MusicService.ACTION_REWIND; + command = MusicService.ACTION_PREVIOUS; break; case KeyEvent.KEYCODE_MEDIA_PAUSE: command = MusicService.ACTION_PAUSE; @@ -126,6 +125,12 @@ public static boolean handleIntent(final Context context, final Intent intent) { case KeyEvent.KEYCODE_MEDIA_PLAY: command = MusicService.ACTION_PLAY; break; + case KeyEvent.KEYCODE_MEDIA_REWIND: + command = MusicService.ACTION_REWIND; + break; + case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: + command = MusicService.ACTION_FASTFORWARD; + break; } if (command != null) { if (action == KeyEvent.ACTION_DOWN) { diff --git a/app/src/main/java/com/kabouzeid/gramophone/service/MusicService.java b/app/src/main/java/com/kabouzeid/gramophone/service/MusicService.java index 9ba9886f1..90c4af02c 100644 --- a/app/src/main/java/com/kabouzeid/gramophone/service/MusicService.java +++ b/app/src/main/java/com/kabouzeid/gramophone/service/MusicService.java @@ -30,6 +30,7 @@ import android.support.v4.media.MediaMetadataCompat; import android.support.v4.media.session.MediaSessionCompat; import android.support.v4.media.session.PlaybackStateCompat; +import android.util.Log; import android.widget.Toast; import androidx.annotation.NonNull; @@ -64,6 +65,7 @@ import com.kabouzeid.gramophone.util.Util; import java.lang.ref.WeakReference; +import java.time.Clock; import java.util.ArrayList; import java.util.List; import java.util.Random; @@ -82,7 +84,10 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP public static final String ACTION_PAUSE = PHONOGRAPH_PACKAGE_NAME + ".pause"; public static final String ACTION_STOP = PHONOGRAPH_PACKAGE_NAME + ".stop"; public static final String ACTION_SKIP = PHONOGRAPH_PACKAGE_NAME + ".skip"; + public static final String ACTION_PREVIOUS = PHONOGRAPH_PACKAGE_NAME + ".previous"; + public static final String ACTION_FASTFORWARD = PHONOGRAPH_PACKAGE_NAME + ".fastforward"; public static final String ACTION_REWIND = PHONOGRAPH_PACKAGE_NAME + ".rewind"; + public static final String ACTION_QUIT = PHONOGRAPH_PACKAGE_NAME + ".quitservice"; public static final String ACTION_PENDING_QUIT = PHONOGRAPH_PACKAGE_NAME + ".pendingquitservice"; public static final String INTENT_EXTRA_PLAYLIST = PHONOGRAPH_PACKAGE_NAME + "intentextra.playlist"; @@ -340,12 +345,18 @@ public int onStartCommand(@Nullable Intent intent, int flags, int startId) { Toast.makeText(getApplicationContext(), R.string.playlist_is_empty, Toast.LENGTH_LONG).show(); } break; - case ACTION_REWIND: + case ACTION_PREVIOUS: back(true); break; case ACTION_SKIP: playNextSong(true); break; + case ACTION_REWIND: + seek(getSongProgressMillis() - 10000); + break; + case ACTION_FASTFORWARD: + seek(getSongProgressMillis() + 10000); + break; case ACTION_STOP: case ACTION_QUIT: pendingQuit = false;