How to read mp3 files from memory?

1

How do I read the mp3 files in the memory? will play the files in the raw folder, but I do not know how to read the ones that the user has on his android ...

I have created these variables

    Context context = this;
    ListView lista;
    ArrayList<Object> elementos = new ArrayList<>();

On the Oncreate I have the following

    lista = (ListView) findViewById(R.id.lista_musica);
    cargardatos();
    ArrayAdapter adapter = new ArrayAdapter(context, R.layout.support_simple_spinner_dropdown_item, elementos);
    lista.setAdapter(adapter);

and outside the OnCreate I have the class loaddata

private void cargardatos() {
    elementos.add("primero");
    elementos.add("segundo");
    elementos.add("tercero");

}

when starting the application shows the following

I want that in the part that says first, second and etc, the music that the user has on his phone is placed, the buttons to play will be created later.

    
asked by Leonardo Henao 23.06.2017 в 07:35
source

1 answer

1

To read a music file, just call setDataSource(archivo) in the following way:

String rutaArchivo = Environment.getExternalStorageDirectory()+"/carpeta/musica.mp3";
MediaPlayer mediaPlayer = new  MediaPlayer();
mediaPlayer.setDataSource(rutaArchivo);
mediaPlayer.prepare();   
mediaPlayer.start()
    
answered by 25.06.2017 в 16:29