I have been trying to play an mp3 audio file in the default media player. Copying the code from here I write my code like this
AlertDialog.Builder dialog = new AlertDialog.Builder(this);
dialog
.setCancelable(true)
.setMessage("File Path: " + path + "\n"
+ "Duration: " + duration + "\n"
+ "File Format: " + format + "\n"
+ "File Status: " + status)
.setTitle("File Information")
.setPositiveButton("Play", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Uri uri = null;
uri = Uri.parse(toPlay);
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(uri, "audio/mp3");
startActivity(intent);
}
})
.setNegativeButton("Delete", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
})
.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
});
where path
and toPlay
are equal to /mnt/sdcard/MUSIC/Aey Nojwan.mp3
.
Now when I press the play button on the dialog
, VLC player open (without making a selection of player from the installed ones) and show a dialog with following error:
VLC encountered an error with this media. Please try refreshing the media library
I tried uninstalling the VLC, but after doing this the play button on my dialog
does nothing. What can be the problem.