Home > Blockchain >  How to Launch default media player by clicking a button from my app
How to Launch default media player by clicking a button from my app

Time:12-28

I have three buttons on my app next, play/pause and back buttons. By clicking on play button I wants to play song from mobile default audio player of mobile and by clicking next and previous buttons I wants to switch songs. Kindly guide how can I achieve this

CodePudding user response:

Try with this

Uri uri = Uri.parse("Your mp3 file url");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);

CodePudding user response:

video player:

File file = new File("fileUri");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "video/*");
startActivity(intent);

and audio player:

File file = new File("fileUri");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "audio/*");
startActivity(intent);
  • Related