[Android] AudioService: re-use Random

Edward Wang git at videolan.org
Fri Jul 18 17:47:23 CEST 2014


vlc-ports/android | branch: master | Edward Wang <edward.c.wang at compdigitec.com> | Fri Jul 18 11:46:40 2014 -0400| [75b8a81301ad063bf8d55402112fac9378710876] | committer: Edward Wang

AudioService: re-use Random

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=75b8a81301ad063bf8d55402112fac9378710876
---

 vlc-android/src/org/videolan/vlc/audio/AudioService.java |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/vlc-android/src/org/videolan/vlc/audio/AudioService.java b/vlc-android/src/org/videolan/vlc/audio/AudioService.java
index 38692d1..e9fc12b 100644
--- a/vlc-android/src/org/videolan/vlc/audio/AudioService.java
+++ b/vlc-android/src/org/videolan/vlc/audio/AudioService.java
@@ -133,6 +133,7 @@ public class AudioService extends Service {
     // Playback management
     private boolean mShuffling = false;
     private RepeatType mRepeating = RepeatType.None;
+    private Random mRandom = null; // Used in shuffling process
 
     // RemoteControlClient-related
     /**
@@ -828,10 +829,11 @@ public class AudioService extends Service {
                             mPrevious.clear();
                         }
                     }
+                    if(mRandom == null) mRandom = new Random();
                     // Find a new index not in mPrevious.
                     do
                     {
-                        mNextIndex = new Random().nextInt(size);
+                        mNextIndex = mRandom.nextInt(size);
                     }
                     while(mNextIndex == mCurrentIndex || mPrevious.contains(mNextIndex));
 



More information about the Android mailing list