this is the intent which opens a chooser from the music app
public void launchMusicPlayer(View view) {
Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i,1);
}
and below is the onActivityResult code to try and obtain the song , but the problem is that the test button when pressed, does not play anything and as i am new to coding i don't know what i am doing wrong.
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK && requestCode == 1) {
final MediaPlayer testSong = new MediaPlayer();
Uri songUri = data.getData();
try {
testSong.setDataSource(this, songUri);
} catch (IOException e) {
e.printStackTrace();
}
testSong.prepareAsync();
test.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
testSong.start();
}
});
}
}