0
votes

I am trying to play an audio file present in res/raw directory using the default audio player from my app.

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(String.format("android.resource://%s/%s/%s",getContext().getPackageName(),"raw","fade")), "audio/*");     

startActivity(intent);

However, every time I am getting exception:

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=android.resource://com.example.android.punjabi/raw/fade typ=audio/* launchParam=MultiScreenLaunchParams { mDisplayId=0 mFlags=0 } }

I have tried out the ways mentioned in here:

Get URI of .mp3 file stored in res/raw folder in android

It still gives me the same exception.

Any help please. I don't want to use the MediaPlayer class to play the audio. I want to use the default audio player on the phone to play it.

1

1 Answers

0
votes

There is no requirement for any device to have an app capable of supporting playing back audio from a Uri using the under-utilized android:resource scheme.

Either:

  • Play it yourself using MediaPlayer, or

  • Copy the contents of that resource to a file, then use FileProvider to serve it up using a content Uri