How can I add a song to my list in Android Studio

0

Hi, I'm doing a music player and one of the tasks that you should do is that when you press a button, a file browser comes up and you search for a song and that song is added to your existing list but I do not know how to get it that file and save it in the raw folder or in my existing list

The app already has 3 predefined songs which I have saved in the raw folder and I want that when looking for a new one it is also added to the list

This is the code of my browser works and I get the route but I do not know how to add it to my song list

public void openFile(View view){
    new ChooserDialog().with(this)
            .withFilter(false, false, "mp3", "wma", "wav", "jpg")// para agregar mas formatos solo agregar un nuevo elemento despues de "wav" eje: "wav", "mp4" ....
            .withStartFile(Environment.getExternalStorageDirectory().getPath()) // ruta en la que inicia el buscador
            .withChosenListener(new ChooserDialog.Result() {
                @Override
                public void onChoosePath(String path, File pathFile) {

                    Toast.makeText(Explorador.this, "FILE: " + path, Toast.LENGTH_SHORT).show();
                }
            })
            .build()
            .show();
}

and there are my variables and my onCreate method

ListView listaCanciones;
List<String> list;
ListAdapter adapter;

MediaPlayer mp;


int posicion = 0;
Button play_pause, btn_repetir;
SeekBar positionBar;
TextView TiempoInicio, TiempoFinal, titulo;
int totalTime;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_explorador);

    play_pause = (Button)findViewById(R.id.btnPlay_Pause);
    listaCanciones = findViewById(R.id.lv);
    TiempoInicio = (TextView)findViewById(R.id.txtTiempoInicio);
    TiempoFinal = (TextView)findViewById(R.id.txtTiempoFinal);
    titulo = (TextView)findViewById(R.id.txtTitulo);


    registerForContextMenu(listaCanciones);

    list = new ArrayList<>();

    //Agregar a la lista las canciones de la carpeta raw
    Field[] fields = R.raw.class.getFields();
    for (int i = 0; i < fields.length; i++){
        list.add(fields[i].getName());
    }


    adapter = new ArrayAdapter<>(this, R.layout.list_view_configuracion, list);
    listaCanciones.setAdapter(adapter);

    listaCanciones.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            if(mp != null ){
                mp.stop();
                mp.release();
            }

            int resID = getResources().getIdentifier(list.get(i), "raw", getPackageName());
            mp = MediaPlayer.create(Explorador.this, resID);
            mp.start();
            play_pause.setBackgroundResource(R.drawable.pausa);
            //Toast.makeText(getApplicationContext(), "Reproduciendo", Toast.LENGTH_SHORT).show();

            //Poner el nombre de la cancion
            titulo.setText(listaCanciones.getItemAtPosition(i).toString());



        }
    });

}
    
asked by Eduardo Noyola 02.10.2018 в 18:47
source

0 answers