Fixed play/pause state being wrong on some possible execution flows.

This commit is contained in:
Felix Ableitner 2014-01-05 19:53:15 +01:00
parent 5b392f0393
commit c69bb01b7b
2 changed files with 21 additions and 7 deletions

View file

@ -300,8 +300,10 @@ public class RouteFragment extends MediaRouteDiscoveryFragment implements
public void onItemClick(AdapterView<?> a, View v, final int position, long id) { public void onItemClick(AdapterView<?> a, View v, final int position, long id) {
if (mListView.getAdapter() == mRouteAdapter) if (mListView.getAdapter() == mRouteAdapter)
playlistMode(mRouteAdapter.getItem(position)); playlistMode(mRouteAdapter.getItem(position));
else else {
mMediaRouterPlayService.getService().play(position); mMediaRouterPlayService.getService().play(position);
changePlayPauseState(true);
}
} }
/** /**
@ -417,6 +419,7 @@ public class RouteFragment extends MediaRouteDiscoveryFragment implements
// Single tap. // Single tap.
mPreviousTapCount = 0; mPreviousTapCount = 0;
s.play(s.getCurrentTrack()); s.play(s.getCurrentTrack());
changePlayPauseState(true);
} }
}; };
if (mPreviousTapCount == 1) if (mPreviousTapCount == 1)
@ -428,7 +431,8 @@ public class RouteFragment extends MediaRouteDiscoveryFragment implements
} }
break; break;
case R.id.next: case R.id.next:
s.playNext(); boolean stillPlaying = s.playNext();
changePlayPauseState(stillPlaying);
break; break;
case R.id.repeat: case R.id.repeat:
s.toggleRepeatEnabled(); s.toggleRepeatEnabled();

View file

@ -315,25 +315,35 @@ public class MediaRouterPlayService extends Service {
/** /**
* Plays the track after current in the playlist. * Plays the track after current in the playlist.
*
* @return True if another item is played, false if the end
* of the playlist is reached.
*/ */
public void playNext() { public boolean playNext() {
if (mCurrentTrack == -1) if (mCurrentTrack == -1)
return; return false;
if (mShuffle) if (mShuffle) {
// Play random item. // Play random item.
play(new Random().nextInt(mPlaylist.size())); play(new Random().nextInt(mPlaylist.size()));
else if (mCurrentTrack + 1 < mPlaylist.size()) return true;
}
else if (mCurrentTrack + 1 < mPlaylist.size()) {
// Playlist not over, play next item. // Playlist not over, play next item.
play(mCurrentTrack + 1); play(mCurrentTrack + 1);
else if (mRepeat) return true;
}
else if (mRepeat) {
// Playlist over, repeat it. // Playlist over, repeat it.
play(0); play(0);
return true;
}
else { else {
// Playlist over, stop playback. // Playlist over, stop playback.
stop(); stop();
if (!mBound) if (!mBound)
stopSelf(); stopSelf();
return false;
} }
} }