Added support for Android File Explorer

This commit is contained in:
Karim Abou Zeid 2017-04-22 16:34:52 +02:00
commit 3561cfd0b7

View file

@ -10,6 +10,7 @@ import android.content.Intent;
import android.content.ServiceConnection; import android.content.ServiceConnection;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Environment;
import android.os.IBinder; import android.os.IBinder;
import android.provider.DocumentsContract; import android.provider.DocumentsContract;
import android.provider.MediaStore; import android.provider.MediaStore;
@ -400,13 +401,22 @@ public class MusicPlayerRemote {
} }
} }
} }
if (songs == null && uri.getPath() != null) { if (songs == null) {
File songFile = null;
if (uri.getAuthority() != null && uri.getAuthority().equals("com.android.externalstorage.documents")) {
songFile = new File(Environment.getExternalStorageDirectory(), uri.getPath().split(":", 2)[1]);
}
if (songFile == null && uri.getPath() != null) {
songFile = new File(uri.getPath());
}
if (songFile != null) {
songs = SongLoader.getSongs(SongLoader.makeSongCursor( songs = SongLoader.getSongs(SongLoader.makeSongCursor(
musicService, musicService,
MediaStore.Audio.AudioColumns.DATA + "=?", MediaStore.Audio.AudioColumns.DATA + "=?",
new String[]{new File(uri.getPath()).getAbsolutePath()} new String[]{songFile.getAbsolutePath()}
)); ));
} }
}
if (songs != null && !songs.isEmpty()) { if (songs != null && !songs.isEmpty()) {
openQueue(songs, 0, true); openQueue(songs, 0, true);
} else { } else {
@ -414,6 +424,7 @@ public class MusicPlayerRemote {
} }
} }
} }
@TargetApi(Build.VERSION_CODES.KITKAT) @TargetApi(Build.VERSION_CODES.KITKAT)
private static String getSongIdFromMediaProvider(Uri uri) { private static String getSongIdFromMediaProvider(Uri uri) {
return DocumentsContract.getDocumentId(uri).split(":")[1]; return DocumentsContract.getDocumentId(uri).split(":")[1];