Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void getMp3Songs() {
- Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
- String selection = MediaStore.Audio.Media.IS_MUSIC + "!=0";
- Cursor cursor = getContentResolver().query(uri, null, selection, null, null);
- if (cursor != null) {
- if (cursor.moveToFirst()) {
- do {
- String name = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.DISPLAY_NAME));
- String artist = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ARTIST));
- String url = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.DATA));
- int songId = cursor.getColumnIndex(MediaStore.Audio.Media._ID);
- arrayList.add(new Songs(songId, name, url));
- } while (cursor.moveToNext());
- }
- cursor.close();
- }
- }
- private void initializePlayer(){
- player = ExoPlayerFactory.newSimpleInstance(new DefaultRenderersFactory(this), new DefaultTrackSelector()
- , new DefaultLoadControl());
- simpleExoPlayerView.setPlayer(player);
- player.setPlayWhenReady(playWhenReady);
- player.seekTo(currentWindow,playbackPosition);
- Uri uri = Uri.parse(url);
- MediaSource mediaSource = buildMediaSource(uri);
- player.prepare(mediaSource, true, false);
- }
- private MediaSource buildMediaSource(Uri uri) {
- return new ExtractorMediaSource(uri,
- new DefaultHttpDataSourceFactory("ua"),
- new DefaultExtractorsFactory(), null, null);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement