0

I want to use default music player in my app. Scenario is,if someone click on the song in the playlist it should be automatically play with default music player of android.

    public void defaultMusic(View v) {
    Intent intent = new Intent();
    intent.setAction(android.content.Intent.ACTION_VIEW);
    File file = new File(String.valueOf(R.raw.sample_audio));
    intent.setDataAndType(Uri.fromFile(file), "audio/*");
    startActivity(intent);
}

But error is coming "Couldn't play the track you requested."

abhi
  • 45
  • 8
  • Where exactly is `file` pointing to? Also, do not use `audio/*` -- use the actual MIME type of the content you are asking to view. – CommonsWare Jul 26 '17 at 11:31
  • you should use deep-linking for it and let the user choice for default or not – Mohit Suthar Jul 26 '17 at 11:32
  • how to use mime type? my content is song mp3. – abhi Jul 26 '17 at 11:33
  • this is not how to read a file from `raw` are the songs already shipped with ur app? or they will be played from sdcard for ex? for more details on playing audio from `raw` check this https://stackoverflow.com/questions/7499605/how-to-play-the-audio-files-directly-from-res-raw-folder – Yazan Jul 26 '17 at 11:37
  • My problem is that i want to use default music player but it is not getting done by this. – abhi Jul 26 '17 at 11:52
  • although you did not answer if the audio files are shipped with the app, then have a look here , Get URI for raw file, https://stackoverflow.com/questions/7966085/raw-folder-url-path – Yazan Jul 26 '17 at 12:11

0 Answers0