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) {
if (mListView.getAdapter() == mRouteAdapter)
playlistMode(mRouteAdapter.getItem(position));
else
else {
mMediaRouterPlayService.getService().play(position);
changePlayPauseState(true);
}
}
/**
@ -417,6 +419,7 @@ public class RouteFragment extends MediaRouteDiscoveryFragment implements
// Single tap.
mPreviousTapCount = 0;
s.play(s.getCurrentTrack());
changePlayPauseState(true);
}
};
if (mPreviousTapCount == 1)
@ -428,7 +431,8 @@ public class RouteFragment extends MediaRouteDiscoveryFragment implements
}
break;
case R.id.next:
s.playNext();
boolean stillPlaying = s.playNext();
changePlayPauseState(stillPlaying);
break;
case R.id.repeat:
s.toggleRepeatEnabled();

View file

@ -315,25 +315,35 @@ public class MediaRouterPlayService extends Service {
/**
* 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)
return;
return false;
if (mShuffle)
if (mShuffle) {
// Play random item.
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.
play(mCurrentTrack + 1);
else if (mRepeat)
return true;
}
else if (mRepeat) {
// Playlist over, repeat it.
play(0);
return true;
}
else {
// Playlist over, stop playback.
stop();
if (!mBound)
stopSelf();
return false;
}
}