private void handleKeyEvent(KeyEvent event) { if (event.getAction() != KeyEvent.ACTION_DOWN || event.getRepeatCount() > 0) { return; } switch (event.getKeyCode()) { case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: case KeyEvent.KEYCODE_HEADSETHOOK: downloadService.togglePlayPause(); break; case KeyEvent.KEYCODE_MEDIA_PREVIOUS: downloadService.previous(); break; case KeyEvent.KEYCODE_MEDIA_NEXT: if (downloadService.getCurrentPlayingIndex() < downloadService.size() - 1) { downloadService.next(); } break; case KeyEvent.KEYCODE_MEDIA_STOP: downloadService.reset(); break; case KeyEvent.KEYCODE_MEDIA_PLAY: downloadService.play(); break; case KeyEvent.KEYCODE_MEDIA_PAUSE: downloadService.pause(); break; default: break; } }
public void serializeDownloadQueue() { State state = new State(); for (DownloadFile downloadFile : downloadService.getDownloads()) { state.songs.add(downloadFile.getSong()); } state.currentPlayingIndex = downloadService.getCurrentPlayingIndex(); state.currentPlayingPosition = downloadService.getPlayerPosition(); Log.i( TAG, "Serialized currentPlayingIndex: " + state.currentPlayingIndex + ", currentPlayingPosition: " + state.currentPlayingPosition); FileUtil.serialize(downloadService, state, FILENAME_DOWNLOADS_SER); }