我正在尝试使用应用程序中的默认音频播放器来播放res / raw目录中存在的音频文件。
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);
但是,每次遇到异常时:
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 } }
我已经尝试了这里提到的方法:
Get URI of .mp3 file stored in res/raw folder in android
它仍然给我同样的异常(exception)。
请帮忙。我不想使用MediaPlayer类播放音频。我想使用手机上的默认音频播放器来播放它。
最佳答案
不需要任何设备具有能够使用未充分利用的Uri
方案支持从android:resource
播放音频的应用程序。
要么:
MediaPlayer
或FileProvider
通过content
为其提供服务Uri
关于android - Android:从res文件启动默认音频 Intent ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48894002/