[Android] Do not start medialibrary scan with video player

Geoffrey Métais git at videolan.org
Wed Sep 13 13:44:42 CEST 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Sep 13 13:43:46 2017 +0200| [5e92f74dacee182524e682b10c3614f75f2fefe2] | committer: Geoffrey Métais

Do not start medialibrary scan with video player

> https://code.videolan.org/videolan/vlc-android/commit/5e92f74dacee182524e682b10c3614f75f2fefe2
---

 .../gui/helpers/hf/StoragePermissionsDelegate.java | 16 +++++++++----
 .../vlc/gui/video/VideoPlayerActivity.java         | 26 +++++++++++++---------
 2 files changed, 27 insertions(+), 15 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/helpers/hf/StoragePermissionsDelegate.java b/vlc-android/src/org/videolan/vlc/gui/helpers/hf/StoragePermissionsDelegate.java
index 1908fe5a1..672368039 100644
--- a/vlc-android/src/org/videolan/vlc/gui/helpers/hf/StoragePermissionsDelegate.java
+++ b/vlc-android/src/org/videolan/vlc/gui/helpers/hf/StoragePermissionsDelegate.java
@@ -48,6 +48,10 @@ import static org.videolan.vlc.util.Permissions.canReadStorage;
 @TargetApi(Build.VERSION_CODES.LOLLIPOP)
 public class StoragePermissionsDelegate extends BaseHeadlessFragment {
 
+    public interface CustomActionController {
+        void onStorageAccessGranted();
+    }
+
     public final static String TAG = "VLC/StorageHF";
 
     private boolean mFirstRun, mUpgrade;
@@ -81,10 +85,14 @@ public class StoragePermissionsDelegate extends BaseHeadlessFragment {
                 // If request is cancelled, the result arrays are empty.
                 final Context ctx = VLCApplication.getAppContext();
                 if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
-                    Intent serviceIntent = new Intent(MediaParsingService.ACTION_INIT, null, ctx, MediaParsingService.class);
-                    serviceIntent.putExtra(StartActivity.EXTRA_FIRST_RUN, mFirstRun);
-                    serviceIntent.putExtra(StartActivity.EXTRA_UPGRADE, mUpgrade);
-                    ctx.startService(serviceIntent);
+                    if (mActivity instanceof CustomActionController) {
+                        ((CustomActionController) mActivity).onStorageAccessGranted();
+                    } else {
+                        final Intent serviceIntent = new Intent(MediaParsingService.ACTION_INIT, null, ctx, MediaParsingService.class);
+                        serviceIntent.putExtra(StartActivity.EXTRA_FIRST_RUN, mFirstRun);
+                        serviceIntent.putExtra(StartActivity.EXTRA_UPGRADE, mUpgrade);
+                        ctx.startService(serviceIntent);
+                    }
                     exit();
                 } else if (mActivity != null) {
                     Permissions.showStoragePermissionDialog(mActivity, false);
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
index 885083e9b..209be4ec9 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -119,6 +119,7 @@ import org.videolan.vlc.gui.dialogs.AdvOptionsDialog;
 import org.videolan.vlc.gui.helpers.OnRepeatListener;
 import org.videolan.vlc.gui.helpers.SwipeDragItemTouchHelperCallback;
 import org.videolan.vlc.gui.helpers.UiTools;
+import org.videolan.vlc.gui.helpers.hf.StoragePermissionsDelegate;
 import org.videolan.vlc.gui.preferences.PreferencesActivity;
 import org.videolan.vlc.gui.tv.audioplayer.AudioPlayerActivity;
 import org.videolan.vlc.interfaces.IPlaybackSettingsController;
@@ -143,9 +144,11 @@ import java.util.ArrayList;
 import java.util.Date;
 import java.util.Locale;
 
-public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.Callback, IVLCVout.OnNewVideoLayoutListener,
-        IPlaybackSettingsController, PlaybackService.Client.Callback, PlaybackService.Callback,
-        PlaylistAdapter.IPlayer, OnClickListener, View.OnLongClickListener, ScaleGestureDetector.OnScaleGestureListener {
+public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.Callback,
+        IVLCVout.OnNewVideoLayoutListener, IPlaybackSettingsController,
+        PlaybackService.Client.Callback, PlaybackService.Callback,PlaylistAdapter.IPlayer,
+        OnClickListener, StoragePermissionsDelegate.CustomActionController,
+        ScaleGestureDetector.OnScaleGestureListener, View.OnLongClickListener {
 
     public final static String TAG = "VLC/VideoPlayerActivity";
 
@@ -1805,13 +1808,6 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
     private void encounteredError() {
         if (isFinishing())
             return;
-        //We may not have the permission to access files
-        if (AndroidUtil.isMarshMallowOrLater && mUri != null &&
-                TextUtils.equals(mUri.getScheme(), "file") &&
-                !Permissions.canReadStorage()) {
-            Permissions.checkReadStoragePermission(this, true);
-            return;
-        }
         /* Encountered Error, exit player with a message */
         mAlertDialog = new AlertDialog.Builder(VideoPlayerActivity.this)
         .setOnCancelListener(new DialogInterface.OnCancelListener() {
@@ -2576,6 +2572,11 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
     @Override
     public void onScaleEnd(ScaleGestureDetector detector) {}
 
+    @Override
+    public void onStorageAccessGranted() {
+        mHandler.sendEmptyMessage(START_PLAYBACK);
+    }
+
     private interface TrackSelectedListener {
         boolean onTrackSelected(int trackID);
     }
@@ -3698,7 +3699,10 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
     @Override
     public void onConnected(PlaybackService service) {
         mService = service;
-        if (!mSwitchingView)
+        //We may not have the permission to access files
+        if (!Permissions.canReadStorage())
+            Permissions.checkReadStoragePermission(this, true);
+        else if (!mSwitchingView)
             mHandler.sendEmptyMessage(START_PLAYBACK);
         mSwitchingView = false;
         mSettings.edit().putBoolean(PreferencesActivity.VIDEO_RESTORE, false).apply();



More information about the Android mailing list