/** * This is called from the thread with a message containing updated info of what's currently * playing. * * @param msg Message object containing currently playing info */ public synchronized boolean handleMessage(Message msg) { final Bundle data = msg.getData(); final ICurrentlyPlaying currentlyPlaying = (ICurrentlyPlaying) data.getSerializable(NowPlayingPollerThread.BUNDLE_CURRENTLY_PLAYING); switch (msg.what) { case NowPlayingPollerThread.MESSAGE_PROGRESS_CHANGED: mPlayStatus = currentlyPlaying.getPlayStatus(); if (currentlyPlaying.isPlaying()) { mPlaylistActivity.setTime(Song.getDuration(currentlyPlaying.getTime() + 1)); } else { mPlaylistActivity.clear(); } return true; case NowPlayingPollerThread.MESSAGE_PLAYLIST_ITEM_CHANGED: mLastPosition = data.getInt(NowPlayingPollerThread.BUNDLE_LAST_PLAYPOSITION); onTrackChanged(currentlyPlaying); return true; case NowPlayingPollerThread.MESSAGE_PLAYSTATE_CHANGED: mPlayListId = data.getInt(NowPlayingPollerThread.BUNDLE_LAST_PLAYLIST); return true; case MESSAGE_PLAYLIST_SIZE: final int size = msg.getData().getInt(BUNDLE_PLAYLIST_SIZE); mPlaylistActivity.setNumItems(size == 0 ? "empty" : size + " tracks"); return true; case NowPlayingPollerThread.MESSAGE_CONNECTION_ERROR: case NowPlayingPollerThread.MESSAGE_RECONFIGURE: mPlayStatus = PlayStatus.UNKNOWN; return true; default: return false; } }