在我的应用程序的 /res/raw/ 文件夹中,我有:file1.ogg file2.ogg ... fileN.ogg
在本地数据库中,我有对文件名的引用,即file1 file2 ... fileN
.
给定其中一个字符串,比如说fileM
,我如何播放包含在其中的音频fileM.ogg
?在这里寻找相关的 Java 代码。
这是我目前看到的:
String name = "plumber";
String link = "/res/raw/" + name + ".ogg";
try {
mp.setDataSource(link); //earlier: mp = new MediaPlayer();
mp.prepare();
mp.start();
} catch (Exception e) {
Toast.makeText(PlayScreen.this, "ERROR: audio player not working.", Toast.LENGTH_LONG).show();
}
我在吐司中收到错误消息。我也试过link
没有“/res/raw”的字符串。
谢谢你。