[Android] Fix Previous indexes stack on media removal
Geoffrey Métais
git at videolan.org
Tue Jul 26 10:58:02 CEST 2016
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Jul 26 10:56:41 2016 +0200| [7c485088d2172bf6cb47aa2abb35cfd3fbf26d64] | committer: Geoffrey Métais
Fix Previous indexes stack on media removal
> https://code.videolan.org/videolan/vlc-android/commit/7c485088d2172bf6cb47aa2abb35cfd3fbf26d64
---
.../src/org/videolan/vlc/PlaybackService.java | 21 +++++++++++++++++----
1 file changed, 17 insertions(+), 4 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/PlaybackService.java b/vlc-android/src/org/videolan/vlc/PlaybackService.java
index 492744e..4dff6eb 100644
--- a/vlc-android/src/org/videolan/vlc/PlaybackService.java
+++ b/vlc-android/src/org/videolan/vlc/PlaybackService.java
@@ -802,7 +802,7 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
* @return True if a media is currently loaded, false otherwise
*/
private boolean hasCurrentMedia() {
- return mCurrentIndex >= 0 && mCurrentIndex < mMediaList.size();
+ return isValidIndex(mCurrentIndex);
}
private final Handler mHandler = new AudioServiceHandler(this);
@@ -1021,8 +1021,17 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
} else {
if(mShuffling) {
- if(mPrevious.size() > 0)
+ if(!mPrevious.isEmpty()){
mPrevIndex = mPrevious.peek();
+ while (!isValidIndex(mPrevIndex)) {
+ mPrevious.remove(mPrevious.size() - 1);
+ if (mPrevious.isEmpty()) {
+ mPrevIndex = -1;
+ break;
+ }
+ mPrevIndex = mPrevious.peek();
+ }
+ }
// If we've played all songs already in shuffle, then either
// reshuffle or stop (depending on RepeatType).
if(mPrevious.size() + 1 == size) {
@@ -1060,6 +1069,10 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
}
}
+ private boolean isValidIndex(int position) {
+ return position >= 0 && position < mMediaList.size();
+ }
+
private void initMediaSession() {
ComponentName mediaButtonEventReceiver = new ComponentName(this,
RemoteControlClientReceiver.class);
@@ -1640,7 +1653,7 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
Log.w(TAG, "Warning: empty media list, nothing to play !");
return;
}
- if (mMediaList.size() > position && position >= 0) {
+ if (isValidIndex(position)) {
mCurrentIndex = position;
} else {
Log.w(TAG, "Warning: positon " + position + " out of bounds");
@@ -1673,7 +1686,7 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
Log.w(TAG, "Warning: empty media list, nothing to play !");
return;
}
- if (index >= 0 && index < mMediaList.size()) {
+ if (isValidIndex(index)) {
mCurrentIndex = index;
} else {
Log.w(TAG, "Warning: index " + index + " out of bounds");
More information about the Android
mailing list