[Android] Fix NPE

Geoffrey Métais git at videolan.org
Thu Nov 12 11:48:57 CET 2015


vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Nov 12 11:28:38 2015 +0100| [2dae81ff7c5080c8b152fce76173932cc67c3be9] | committer: Geoffrey Métais

Fix NPE

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

 vlc-android/src/org/videolan/vlc/gui/preferences/Advanced.java  |    5 +++--
 vlc-android/src/org/videolan/vlc/gui/preferences/Developer.java |    6 +++---
 .../org/videolan/vlc/gui/preferences/PreferencesFragment.java   |    7 +++----
 .../videolan/vlc/gui/preferences/PreferencesPerformances.java   |    5 +++--
 vlc-android/src/org/videolan/vlc/util/VLCInstance.java          |    6 +++---
 vlc-android/src/org/videolan/vlc/util/VLCOptions.java           |    4 ++--
 6 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/preferences/Advanced.java b/vlc-android/src/org/videolan/vlc/gui/preferences/Advanced.java
index 5915876..674aec8 100644
--- a/vlc-android/src/org/videolan/vlc/gui/preferences/Advanced.java
+++ b/vlc-android/src/org/videolan/vlc/gui/preferences/Advanced.java
@@ -178,8 +178,9 @@ public class Advanced extends BasePreferenceFragment implements SharedPreference
             case "aout":
             case "network_caching":
             case "vout":
-                VLCInstance.restart(getActivity());
-                ((PreferencesActivity)getActivity()).restartMediaPlayer();
+                VLCInstance.restart();
+                if (getActivity() != null )
+                    ((PreferencesActivity)getActivity()).restartMediaPlayer();
         }
     }
 }
diff --git a/vlc-android/src/org/videolan/vlc/gui/preferences/Developer.java b/vlc-android/src/org/videolan/vlc/gui/preferences/Developer.java
index cb9a5d5..e10c392 100644
--- a/vlc-android/src/org/videolan/vlc/gui/preferences/Developer.java
+++ b/vlc-android/src/org/videolan/vlc/gui/preferences/Developer.java
@@ -24,7 +24,6 @@
 package org.videolan.vlc.gui.preferences;
 
 import android.Manifest;
-import android.content.Context;
 import android.content.Intent;
 import android.content.SharedPreferences;
 import android.content.pm.PackageManager;
@@ -85,8 +84,9 @@ public class Developer extends BasePreferenceFragment implements SharedPreferenc
         switch (key){
             case "dev_hardware_decoder":
             case "enable_verbose_mode":
-                VLCInstance.restart(getActivity());
-                ((PreferencesActivity)getActivity()).restartMediaPlayer();
+                VLCInstance.restart();
+                if (getActivity() != null )
+                    ((PreferencesActivity)getActivity()).restartMediaPlayer();
         }
     }
 }
diff --git a/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesFragment.java b/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesFragment.java
index c559da8..507a6ff 100644
--- a/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesFragment.java
@@ -23,14 +23,12 @@
 
 package org.videolan.vlc.gui.preferences;
 
-import android.app.Fragment;
 import android.content.Intent;
 import android.content.SharedPreferences;
 import android.os.Bundle;
 import android.support.v7.preference.ListPreference;
 import android.support.v7.preference.Preference;
 import android.support.v7.preference.PreferenceManager;
-import android.util.Log;
 
 import org.videolan.vlc.R;
 import org.videolan.vlc.VLCApplication;
@@ -84,8 +82,9 @@ public class PreferencesFragment extends BasePreferenceFragment implements Share
     public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
         if(key.equalsIgnoreCase("hardware_acceleration")
                 || key.equalsIgnoreCase("subtitle_text_encoding")) {
-            VLCInstance.restart(getActivity());
-            ((PreferencesActivity)getActivity()).restartMediaPlayer();
+            VLCInstance.restart();
+            if (getActivity() != null )
+                ((PreferencesActivity)getActivity()).restartMediaPlayer();
         }
     }
 
diff --git a/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesPerformances.java b/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesPerformances.java
index 31a06e3..d70a050 100644
--- a/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesPerformances.java
+++ b/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesPerformances.java
@@ -59,8 +59,9 @@ public class PreferencesPerformances extends BasePreferenceFragment implements S
             case "deblocking":
             case "enable_frame_skip":
             case "enable_time_stretching_audio":
-                VLCInstance.restart(getActivity());
-                ((PreferencesActivity)getActivity()).restartMediaPlayer();
+                VLCInstance.restart();
+                if (getActivity() != null )
+                    ((PreferencesActivity)getActivity()).restartMediaPlayer();
         }
     }
 }
diff --git a/vlc-android/src/org/videolan/vlc/util/VLCInstance.java b/vlc-android/src/org/videolan/vlc/util/VLCInstance.java
index 3e77af4..dc45ded 100644
--- a/vlc-android/src/org/videolan/vlc/util/VLCInstance.java
+++ b/vlc-android/src/org/videolan/vlc/util/VLCInstance.java
@@ -47,7 +47,7 @@ public class VLCInstance {
                 throw new IllegalStateException("LibVLC initialisation failed: " + VLCUtil.getErrorMsg());
             }
 
-            sLibVLC = new LibVLC(VLCOptions.getLibOptions(context));
+            sLibVLC = new LibVLC(VLCOptions.getLibOptions());
             LibVLC.setOnNativeCrashListener(new LibVLC.OnNativeCrashListener() {
                 @Override
                 public void onNativeCrash() {
@@ -61,10 +61,10 @@ public class VLCInstance {
         return sLibVLC;
     }
 
-    public static synchronized void restart(Context context) throws IllegalStateException {
+    public static synchronized void restart() throws IllegalStateException {
         if (sLibVLC != null) {
             sLibVLC.release();
-            sLibVLC = new LibVLC(VLCOptions.getLibOptions(context));
+            sLibVLC = new LibVLC(VLCOptions.getLibOptions());
         }
     }
 
diff --git a/vlc-android/src/org/videolan/vlc/util/VLCOptions.java b/vlc-android/src/org/videolan/vlc/util/VLCOptions.java
index 0418c7f..e1c82b0 100644
--- a/vlc-android/src/org/videolan/vlc/util/VLCOptions.java
+++ b/vlc-android/src/org/videolan/vlc/util/VLCOptions.java
@@ -50,8 +50,8 @@ public class VLCOptions {
     public static final int HW_ACCELERATION_DECODING = 1;
     public static final int HW_ACCELERATION_FULL = 2;
 
-    public static ArrayList<String> getLibOptions(Context context) {
-        final SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
+    public static ArrayList<String> getLibOptions() {
+        final SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(VLCApplication.getAppContext());
 
         ArrayList<String> options = new ArrayList<String>(50);
 



More information about the Android mailing list