[Android] Trigger threads sooner and prevent NPE

Geoffrey Métais git at videolan.org
Wed Mar 11 19:14:26 CET 2015


vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Mar 11 19:13:55 2015 +0100| [e5a987870bbceb71828d899262f30c257ac639f4] | committer: Geoffrey Métais

Trigger threads sooner and prevent NPE

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

 .../videolan/vlc/gui/video/MediaInfoFragment.java  |   52 +++++++++-----------
 1 file changed, 24 insertions(+), 28 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 53af358..1c40e56 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/MediaInfoFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/MediaInfoFragment.java
@@ -20,27 +20,6 @@
 
 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;
-import org.videolan.libvlc.Media;
-import org.videolan.libvlc.util.Extensions;
-import org.videolan.vlc.MediaWrapper;
-import org.videolan.vlc.MediaLibrary;
-import org.videolan.vlc.R;
-import org.videolan.vlc.gui.MainActivity;
-import org.videolan.vlc.util.BitmapUtil;
-import org.videolan.vlc.util.Strings;
-import org.videolan.vlc.util.Util;
-import org.videolan.vlc.util.WeakHandler;
-
 import android.content.res.Configuration;
 import android.graphics.Bitmap;
 import android.graphics.Bitmap.Config;
@@ -55,11 +34,27 @@ import android.view.LayoutInflater;
 import android.view.View;
 import android.view.View.OnClickListener;
 import android.view.ViewGroup;
-import android.widget.Button;
 import android.widget.ImageButton;
 import android.widget.ImageView;
 import android.widget.TextView;
 
+import org.videolan.libvlc.LibVLC;
+import org.videolan.libvlc.Media;
+import org.videolan.libvlc.util.Extensions;
+import org.videolan.vlc.MediaLibrary;
+import org.videolan.vlc.MediaWrapper;
+import org.videolan.vlc.R;
+import org.videolan.vlc.gui.MainActivity;
+import org.videolan.vlc.util.BitmapUtil;
+import org.videolan.vlc.util.Strings;
+import org.videolan.vlc.util.Util;
+import org.videolan.vlc.util.WeakHandler;
+
+import java.io.File;
+import java.nio.ByteBuffer;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
 public class MediaInfoFragment extends ListFragment {
 
     public final static String TAG = "VLC/MediaInfoFragment";
@@ -81,7 +76,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;
+    ExecutorService mThreadPoolExecutor;
 
     @Override
     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
@@ -95,6 +90,10 @@ public class MediaInfoFragment extends ListFragment {
         mDelete = (ImageButton) v.findViewById(R.id.info_delete);
         mSubtitles = (ImageView) v.findViewById(R.id.info_subtitles);
 
+        mThreadPoolExecutor = Executors.newFixedThreadPool(2);
+        mThreadPoolExecutor.submit(mCheckFile);
+        mThreadPoolExecutor.submit(mLoadImage);
+
         mPathView.setText(mItem == null ? "" : Uri.decode(mItem.getLocation().substring(7)));
         mPlayButton.setOnClickListener(new OnClickListener() {
             @Override
@@ -136,15 +135,12 @@ public class MediaInfoFragment extends ListFragment {
 
         ((ActionBarActivity) getActivity()).getSupportActionBar().setTitle(mItem.getTitle());
         mLengthView.setText(Strings.millisToString(mItem.getLength()));
-
-        threadPoolExecutor = Executors.newFixedThreadPool(2);
-        threadPoolExecutor.submit(mCheckFile);
-        threadPoolExecutor.submit(mLoadImage);
     }
 
     public void onStop(){
         super.onStop();
-        threadPoolExecutor.shutdownNow();
+        if (mThreadPoolExecutor != null)
+            mThreadPoolExecutor.shutdownNow();
     }
 
     public void setMediaLocation(String MRL) {



More information about the Android mailing list