[Android] Fix Previous indexes stack on media removal
Geoffrey Métais
git at videolan.org
Tue Jul 26 10:58:43 CEST 2016
vlc-android | branch: 2.0.x | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Jul 26 10:56:41 2016 +0200| [b787d065d52845eab44a699f2079c0380811cf74] | committer: Geoffrey Métais
Fix Previous indexes stack on media removal
(cherry picked from commit 7c485088d2172bf6cb47aa2abb35cfd3fbf26d64)
> https://code.videolan.org/videolan/vlc-android/commit/b787d065d52845eab44a699f2079c0380811cf74
---
.../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 7b2e550..9f60619 100644
--- a/vlc-android/src/org/videolan/vlc/PlaybackService.java
+++ b/vlc-android/src/org/videolan/vlc/PlaybackService.java
@@ -811,7 +811,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);
@@ -1030,8 +1030,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) {
@@ -1069,6 +1078,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);
@@ -1659,7 +1672,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");
@@ -1692,7 +1705,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