在默认音乐播放器中播放原始音频文件



我的应用程序在原始文件夹中有音频文件。现在,每当应用程序启动时,这些音频文件都应该使用默认的音乐播放器播放。我尝试了以下代码应用程序崩溃,并显示"找不到处理此意图的活动"。

Intent intent = new Intent();
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.setAction(Intent.ACTION_VIEW);    
intent.setDataAndType(Uri.parse("companion.harman.com.ceshuclient/res/raw/fav.mp3"), "audio/*");
startActivity(intent);

使用"MediaPlayer"对象可以播放相同的音频文件,但这并不是我想要实现的。

任何示例代码或链接都会有所帮助。

提前感谢。

请尝试以下操作(其中mp3file是原始文件夹中不带扩展名的文件名。请仅使用小写字符(:

MediaPlayer player = MediaPlayer(this,R.raw.mp3file);
player.prepare();
player.start();
player.stop();
player.reset();
player.release();
player = null;

这是演示源代码的链接,可以播放mp3文件

最新更新