@Override public void onDestroy() { mHandler.removeCallbacksAndMessages(null); mMediaPlayerController.destroy(); mMediaPlayerController = null; super.onDestroy(); }
@Override public void handleMessage(Message msg) { try { switch (msg.what) { case PLAY_ACTION: Log.i(TAG, "Execute PLAY_ACTION"); mMediaPlayerController.setCurrentState(TransportState.PLAYING); mPlayPauseButton.setImageResource(R.drawable.beyond_holo_light_pause); // Start syncing mMediaPlayerController.startUpdateSeekBar(); break; case PAUSE_ACTION: Log.i(TAG, "Execute PAUSE_ACTION"); mMediaPlayerController.setCurrentState(TransportState.PAUSED_PLAYBACK); mPlayPauseButton.setImageResource(R.drawable.beyond_holo_light_play); mMediaPlayerController.pauseUpdateSeekBar(); break; case STOP_ACTION: Log.i(TAG, "Execute STOP_ACTION"); mMediaPlayerController.setCurrentState(TransportState.STOPPED); mPlayPauseButton.setImageResource(R.drawable.beyond_holo_light_play); mMediaPlayerController.pauseUpdateSeekBar(); break; case GET_MEDIA_INFO_ACTION: MediaInfo mediaInfo = (MediaInfo) msg.obj; if (mediaInfo != null) { Log.i(TAG, "Execute GET_MEDIA_INFO_ACTION:" + mediaInfo); } break; case GET_POSITION_INFO_ACTION: PositionInfo positionInfo = (PositionInfo) msg.obj; Log.i("myTag", "case GET_POSITION_INFO_ACTION... " + positionInfo.toString()); if (positionInfo != null) { // Set rel time and duration time. String relTime = positionInfo.getRelTime(); String trackDuration = positionInfo.getTrackDuration(); mRelTimeText.setText(relTime); mTrackDurationText.setText(trackDuration); int elapsedSeconds = (int) positionInfo.getTrackElapsedSeconds(); int durationSeconds = (int) positionInfo.getTrackDurationSeconds(); mSeekBar.setProgress(elapsedSeconds); mSeekBar.setMax(durationSeconds); Log.d(TAG, "elapsedSeconds:" + elapsedSeconds); Log.d(TAG, "durationSeconds:" + durationSeconds); // Record the current track's duration seconds mTrackDurationSeconds = durationSeconds; } break; case RESUME_SEEKBAR_ACTION: mMediaPlayerController.startUpdateSeekBar(); break; case GET_VOLUME_ACTION: // Get the current volume from arg1. SystemManager.getInstance().setDeviceVolume(msg.arg1); break; case SET_VOLUME_ACTION: SystemManager.getInstance().setDeviceVolume(msg.arg1); PlaybackCommand.setVolume(msg.arg1); break; } } catch (InterruptedException e) { Log.e(TAG, "SetCurrentStatus InterruptedException:" + e.getMessage()); } catch (ExecutionException e) { Log.e(TAG, "SetCurrentStatus ExecutionException:" + e.getMessage()); } }