Android Launching Music Player Using Intent

Android launching music player using intent

I found one way to do this.

Intent intent = new Intent();  
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(YOUR_SONG_PATH), "audio/*");
startActivity(intent);

Launching Media Player using Intent

I think the best option is to use a chooser activity, where the user can choose his favorite media player.

Intent viewIntent = new Intent(Intent.ACTION_VIEW);
File file = new File((String) ((TextView) item).getText());
viewIntent.setDataAndType(Uri.fromFile(file), "audio/*");
startActivity(Intent.createChooser(viewIntent, null));

By the way, that way of passing the file name seems a bit weird to me. I would consider changing it.

I am not sure, but you should be able to see your own player in the chooser if you declare the corresponding intent-filters.



Related Topics



Leave a reply



Submit