[Android] Add open from Uri methods for PlaybackService
Geoffrey Métais
git at videolan.org
Thu Nov 5 14:25:53 CET 2015
vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Nov 5 14:09:31 2015 +0100| [0a08c4d1e13076f6701c54727d385665e13ba491] | committer: Geoffrey Métais
Add open from Uri methods for PlaybackService
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=0a08c4d1e13076f6701c54727d385665e13ba491
---
.../src/org/videolan/vlc/PlaybackService.java | 15 ++++++++---
vlc-android/src/org/videolan/vlc/util/Util.java | 26 +++++++++++++++++---
2 files changed, 35 insertions(+), 6 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/PlaybackService.java b/vlc-android/src/org/videolan/vlc/PlaybackService.java
index 050c3c5..14f928c 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;
@@ -77,6 +78,7 @@ import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Calendar;
+import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Random;
@@ -1560,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