[Android] Return original media if not found in medialibrary

Geoffrey Métais git at videolan.org
Tue May 30 17:03:39 CEST 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue May 30 17:02:54 2017 +0200| [64370a06be9871f2612180a87d4af741efdc4049] | committer: Geoffrey Métais

Return original media if not found in medialibrary

> https://code.videolan.org/videolan/vlc-android/commit/64370a06be9871f2612180a87d4af741efdc4049
---

 .../src/org/videolan/medialibrary/Medialibrary.java       |  8 +++++---
 vlc-android/src/org/videolan/vlc/PlaybackService.java     |  4 ++--
 .../org/videolan/vlc/gui/video/VideoPlayerActivity.java   | 15 ++++++---------
 3 files changed, 13 insertions(+), 14 deletions(-)

diff --git a/medialibrary/src/org/videolan/medialibrary/Medialibrary.java b/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
index b75afb7b3..585140a1d 100644
--- a/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
+++ b/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
@@ -263,12 +263,14 @@ public class Medialibrary {
     public MediaWrapper findMedia(MediaWrapper mw) {
         if (mIsInitiated && mw != null && mw.getId() == 0L) {
             Uri uri = mw.getUri();
-            mw = getMedia(uri);
-            if (mw == null  && TextUtils.equals("file", uri.getScheme()) &&
+            MediaWrapper libraryMedia = getMedia(uri);
+            if (libraryMedia == null && TextUtils.equals("file", uri.getScheme()) &&
                     uri.getPath() != null && uri.getPath().startsWith("/sdcard")) {
                 uri = Tools.convertLocalUri(uri);
-                mw = getMedia(uri);
+                libraryMedia = getMedia(uri);
             }
+            if (libraryMedia != null)
+                return libraryMedia;
         }
         return mw;
     }
diff --git a/vlc-android/src/org/videolan/vlc/PlaybackService.java b/vlc-android/src/org/videolan/vlc/PlaybackService.java
index 5015e9065..e3ac3cd08 100644
--- a/vlc-android/src/org/videolan/vlc/PlaybackService.java
+++ b/vlc-android/src/org/videolan/vlc/PlaybackService.java
@@ -1964,9 +1964,9 @@ public class PlaybackService extends MediaBrowserServiceCompat implements IVLCVo
                     @Override
                     public void run() {
                         long id = mw.getId();
-                        if (id == 0) {
+                        if (id == 0L) {
                             MediaWrapper media = mMedialibrary.findMedia(mw);
-                            if (media != null)
+                            if (media != null && media.getId() != 0L)
                                 id = media.getId();
                             else {
                                 media = mMedialibrary.addMedia(mw.getUri().toString());
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 3b723bc8d..0cba90c52 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -2583,7 +2583,9 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
                         if (trackID < -1 || mService == null)
                             return false;
                         mService.setAudioTrack(trackID);
-                        mMedialibrary.findMedia(mService.getCurrentMediaWrapper()).setLongMeta(mMedialibrary, MediaWrapper.META_AUDIOTRACK, trackID);
+                        MediaWrapper mw = mMedialibrary.findMedia(mService.getCurrentMediaWrapper());
+                        if (mw != null && mw.getId() != 0L)
+                            mw.setLongMeta(mMedialibrary, MediaWrapper.META_AUDIOTRACK, trackID);
                         return true;
                     }
                 });
@@ -2598,7 +2600,9 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
                         if (trackID < -1 || mService == null)
                             return false;
                         mService.setSpuTrack(trackID);
-                        mMedialibrary.findMedia(mService.getCurrentMediaWrapper()).setLongMeta(mMedialibrary, MediaWrapper.META_SUBTITLE_TRACK, trackID);
+                        MediaWrapper mw = mMedialibrary.findMedia(mService.getCurrentMediaWrapper());
+                        if (mw != null && mw.getId() != 0L)
+                            mw.setLongMeta(mMedialibrary, MediaWrapper.META_SUBTITLE_TRACK, trackID);
                         return true;
                     }
                 });
@@ -2971,13 +2975,6 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
         }
         int time = (int) getTime();
         int length = (int) mService.getLength();
-        if (length == 0) {
-            MediaWrapper media = mService.getCurrentMediaWrapper();
-            if (media.getId() == 0)
-                media = mMedialibrary.findMedia(media);
-            if (media != null)
-                length = (int) media.getLength();
-        }
 
         // Update all view elements
         if (mSeekbar != null) {



More information about the Android mailing list