Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. public void getMp3Songs() {
  2. Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
  3. String selection = MediaStore.Audio.Media.IS_MUSIC + "!=0";
  4. Cursor cursor = getContentResolver().query(uri, null, selection, null, null);
  5. if (cursor != null) {
  6. if (cursor.moveToFirst()) {
  7. do {
  8. String name = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.DISPLAY_NAME));
  9. String artist = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ARTIST));
  10. String url = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.DATA));
  11. int songId = cursor.getColumnIndex(MediaStore.Audio.Media._ID);
  12. arrayList.add(new Songs(songId, name, url));
  13.  
  14.  
  15. } while (cursor.moveToNext());
  16.  
  17. }
  18.  
  19. cursor.close();
  20. }
  21. }
  22.  
  23. private void initializePlayer(){
  24. player = ExoPlayerFactory.newSimpleInstance(new DefaultRenderersFactory(this), new DefaultTrackSelector()
  25. , new DefaultLoadControl());
  26.  
  27. simpleExoPlayerView.setPlayer(player);
  28. player.setPlayWhenReady(playWhenReady);
  29. player.seekTo(currentWindow,playbackPosition);
  30.  
  31. Uri uri = Uri.parse(url);
  32. MediaSource mediaSource = buildMediaSource(uri);
  33. player.prepare(mediaSource, true, false);
  34. }
  35.  
  36. private MediaSource buildMediaSource(Uri uri) {
  37. return new ExtractorMediaSource(uri,
  38. new DefaultHttpDataSourceFactory("ua"),
  39. new DefaultExtractorsFactory(), null, null);
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement