0

How to pass uri to mediaSource in Android Q since MediaStore.Audio.Media.DATA is deprecated

Earlier (Below Api 29 / Android 10/ Q) This is what i was using

mediaSource = new ProgressiveMediaSource. Factory(dataSourceFactory).createMediaSource(Uri.parse(SongsForQueue.get(i)._path)); simpleExoPlayer.prepare(mediaSource); simpleExoPlayer.setPlayWhenReady(true);

Where SongsForQueue.get(i)._path was the path of the file which we got from MediaStore.Audio.Media.DATA since Android Q deprecated MediaStore.Audio.Media.DATA what can we use

Android suggests

https://stackoverflow.com/a/59037794

use

ContentResolver#openFileDescriptor(Uri, String).

how can we do that any help would be useful

1234567
  • 2,226
  • 4
  • 24
  • 69

1 Answers1

-1

I solved this:

long mediaId = //composition id in media store
Uri uri = ContentUris.withAppendedId(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, mediaId);

DataSpec dataSpec = new DataSpec(uri);
ContentDataSource dataSource = new ContentDataSource(context);
dataSource.open(dataSpec);

DataSource.Factory factory = () -> dataSource;
MediaSource mediaSource = new ProgressiveMediaSource.Factory(factory).createMediaSource(uri);
player.prepare(mediaSource);//your player

Exoplayer version: 2.11.3

Anrimian
  • 4,257
  • 4
  • 22
  • 30
  • the question is about how to use ContentResolver#openFileDescriptor , the uri parse id is a known method – 1234567 Apr 01 '20 at 15:35