[Android] Add open from Uri methods for PlaybackService
Geoffrey Métais
git at videolan.org
Fri Nov 6 13:37:51 CET 2015
vlc-ports/android | branch: playlist | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Nov 5 14:09:31 2015 +0100| [c6f0d4516c02290f309d7839bdb2e6a5c64c03d1] | committer: Geoffrey Métais
Add open from Uri methods for PlaybackService
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=c6f0d4516c02290f309d7839bdb2e6a5c64c03d1
---
.../src/org/videolan/vlc/PlaybackService.java | 14 ++++++++---
vlc-android/src/org/videolan/vlc/util/Util.java | 26 +++++++++++++++++---
2 files changed, 34 insertions(+), 6 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/PlaybackService.java b/vlc-android/src/org/videolan/vlc/PlaybackService.java
index 604e245..dd60a0d 100644
--- a/vlc-android/src/org/videolan/vlc/PlaybackService.java
+++ b/vlc-android/src/org/videolan/vlc/PlaybackService.java
@@ -55,6 +55,7 @@ import android.support.v4.media.session.PlaybackStateCompat;
import android.support.v7.app.NotificationCompat;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
+import android.text.TextUtils;
import android.util.Log;
import android.widget.Toast;
@@ -1561,10 +1562,17 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
}
@MainThread
+ public void loadUri(Uri uri) {
+ String path = uri.getPath();
+ if (TextUtils.equals(uri.getScheme(), "content")) {
+ path = "file://"+Util.getPathFromURI(uri);
+ }
+ loadLocation(path);
+ }
+
+ @MainThread
public void loadLocation(String mediaPath) {
- ArrayList <String> arrayList = new ArrayList<String>();
- arrayList.add(mediaPath);
- loadLocations(arrayList, 0);
+ loadLocations(Collections.singletonList(mediaPath), 0);
}
@MainThread
diff --git a/vlc-android/src/org/videolan/vlc/util/Util.java b/vlc-android/src/org/videolan/vlc/util/Util.java
index 8f9d767..78c85ff 100644
--- a/vlc-android/src/org/videolan/vlc/util/Util.java
+++ b/vlc-android/src/org/videolan/vlc/util/Util.java
@@ -30,6 +30,7 @@ import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.res.TypedArray;
+import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.preference.PreferenceManager;
@@ -41,10 +42,7 @@ import android.util.TypedValue;
import android.view.View;
import android.widget.TextView;
-import org.videolan.libvlc.LibVLC;
-import org.videolan.libvlc.Media;
import org.videolan.libvlc.util.AndroidUtil;
-import org.videolan.vlc.MediaLibrary;
import org.videolan.vlc.MediaWrapper;
import org.videolan.vlc.PlaybackService;
import org.videolan.vlc.R;
@@ -251,6 +249,15 @@ public class Util {
});
}
+ public static void openUri(final Context context, final Uri uri){
+ new DialogCallback(context, new DialogCallback.Runnable() {
+ @Override
+ public void run(PlaybackService service) {
+ service.loadUri(uri);
+ }
+ });
+ }
+
public static void openStream(final Context context, final String uri){
new DialogCallback(context, new DialogCallback.Runnable() {
@Override
@@ -277,6 +284,19 @@ public class Util {
}
}
+ public static String getPathFromURI(Uri contentUri) {
+ Cursor cursor = null;
+ try {
+ String[] proj = { MediaStore.Images.Media.DATA };
+ cursor = VLCApplication.getAppContext().getContentResolver().query(contentUri, proj, null, null, null);
+ int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
+ cursor.moveToFirst();
+ return cursor.getString(column_index);
+ } finally {
+ close(cursor);
+ }
+ }
+
public static String getMediaArtist(Context ctx, MediaWrapper media) {
final String artist = media.getArtist();
return artist != null ? artist : getMediaString(ctx, R.string.unknown_artist);
More information about the Android
mailing list