I have multiple audio files in res/raw
folder. I showing ListView
that contains audio files name. I want to play the corresponding audio file when user select into the ListView
. I have used setDataSource(path)
, but it showing error while playing. How play the audio files directly from that folder? Or Is there any other way?
add this code in onItemClickListener.
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View view, int position,long id) {
TextView txtView=(TextView)view.findViewById(R.id.txt_view);
String fname=txtView.getText().toString().toLowerCase();
int resID=getResources().getIdentifier(fname, "raw", getPackageName());
MediaPlayer mediaPlayer=MediaPlayer.create(this,resID);
mediaPlayer.start();
}
});