[Android] Use threadpool in MediaInfo

Geoffrey Métais git at videolan.org
Fri Feb 20 10:45:09 CET 2015


vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Feb 20 10:18:21 2015 +0100| [0514949ddd9809227b4fbac2c9410d65557baec8] | committer: Geoffrey Métais

Use threadpool in MediaInfo

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

 .../videolan/vlc/gui/video/MediaInfoFragment.java    |   18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/video/MediaInfoFragment.java b/vlc-android/src/org/videolan/vlc/gui/video/MediaInfoFragment.java
index 01fdf96..9a7c524 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/MediaInfoFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/MediaInfoFragment.java
@@ -22,7 +22,11 @@ package org.videolan.vlc.gui.video;
 
 import java.io.File;
 import java.nio.ByteBuffer;
+import java.util.ArrayList;
 import java.util.Locale;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadPoolExecutor;
 
 import org.videolan.libvlc.LibVLC;
 import org.videolan.libvlc.LibVlcUtil;
@@ -76,6 +80,7 @@ public class MediaInfoFragment extends ListFragment {
     private final static int HIDE_DELETE = 3;
     private final static int EXIT = 4;
     private final static int SHOW_SUBTITLES = 5;
+    ExecutorService threadPoolExecutor;
 
     @Override
     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
@@ -133,8 +138,14 @@ public class MediaInfoFragment extends ListFragment {
         ((ActionBarActivity) getActivity()).getSupportActionBar().setTitle(mItem.getTitle());
         mLengthView.setText(Strings.millisToString(mItem.getLength()));
 
-        new Thread(mLoadImage).start();
-        new Thread(mCheckFile).start();
+        threadPoolExecutor = Executors.newFixedThreadPool(2);
+        threadPoolExecutor.submit(mCheckFile);
+        threadPoolExecutor.submit(mLoadImage);
+    }
+
+    public void onStop(){
+        super.onStop();
+        threadPoolExecutor.shutdownNow();
     }
 
     public void setMediaLocation(String MRL) {
@@ -225,6 +236,9 @@ public class MediaInfoFragment extends ListFragment {
             if (b == null) // We were not able to create a thumbnail for this item.
                 return;
 
+            if (Thread.interrupted()) {
+                return;
+            }
             mImage.copyPixelsFromBuffer(ByteBuffer.wrap(b));
             mImage = BitmapUtil.cropBorders(mImage, width, height);
 



More information about the Android mailing list