[Android] Get title of shared media from other apps

Geoffrey Métais git at videolan.org
Fri Oct 6 15:16:07 CEST 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Oct  6 15:14:13 2017 +0200| [389d5fc6faf4e76651ac04c6747676e1914ac6d1] | committer: Geoffrey Métais

Get title of shared media from other apps

> https://code.videolan.org/videolan/vlc-android/commit/389d5fc6faf4e76651ac04c6747676e1914ac6d1
---

 vlc-android/src/org/videolan/vlc/PlaybackService.java | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/vlc-android/src/org/videolan/vlc/PlaybackService.java b/vlc-android/src/org/videolan/vlc/PlaybackService.java
index e071dec0d..f5bef23df 100644
--- a/vlc-android/src/org/videolan/vlc/PlaybackService.java
+++ b/vlc-android/src/org/videolan/vlc/PlaybackService.java
@@ -33,6 +33,7 @@ import android.content.Intent;
 import android.content.IntentFilter;
 import android.content.ServiceConnection;
 import android.content.SharedPreferences;
+import android.database.Cursor;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
 import android.media.AudioManager;
@@ -47,6 +48,7 @@ import android.os.Message;
 import android.os.PowerManager;
 import android.os.SystemClock;
 import android.preference.PreferenceManager;
+import android.provider.OpenableColumns;
 import android.support.annotation.MainThread;
 import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
@@ -1982,6 +1984,8 @@ public class PlaybackService extends MediaBrowserServiceCompat implements IVLCVo
         mParsed = false;
         mSwitchingToVideo = false;
         mPausable = mSeekable = true;
+        if (TextUtils.equals(mw.getUri().getScheme(), "content"))
+            retrieveMediaTitle(mw);
         final Media media = new Media(VLCInstance.get(), FileUtils.getUri(mw.getUri()));
         VLCOptions.setMediaOptions(media, this, flags | mw.getFlags());
 
@@ -2057,6 +2061,19 @@ public class PlaybackService extends MediaBrowserServiceCompat implements IVLCVo
         }
     }
 
+    private void retrieveMediaTitle(MediaWrapper mw) {
+        final Cursor returnCursor = getContentResolver().query(mw.getUri(), null, null, null, null);
+        if (returnCursor == null)
+            return;
+        final int nameIndex = returnCursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
+        if (nameIndex > -1 && returnCursor.getCount() > 0) {
+            returnCursor.moveToFirst();
+            if (!returnCursor.isNull(nameIndex))
+                mw.setTitle(returnCursor.getString(nameIndex));
+        }
+        Util.close(returnCursor);
+    }
+
     /**
      * Use this function to play a media inside whatever MediaList LibVLC is following.
      *



More information about the Android mailing list