【发布时间】:2021-07-15 18:01:43
【问题描述】:
我正在开发一个应用程序,对于特定的选定项目,应分配特定的 .mp3。 (就像我选择 Dachshund,然后当我的函数这样说时,我会播放 dachshund_1.mp3、dachshund_2.mp3 等)。是否有可能以某种方式创建一个包含特定名称的变量,然后将其分配给 mediaplayer.create?
我想做的如下所示:
// I have a function here that returns with the specific string // I have a cnt variable in the code which helps determine which text and sound comes now
fun DogHandler(cnt:Int, receiptName: String) :String
{
return dogName + "_" +cnt.toString()
}
这个函数被调用,它返回的字符串应该去媒体播放器。 Cnt 比方说 10
var tmp = DogHandler(dachshund, cnt); // tmp = dachsund_10
mediaPlayer = MediaPlayer.create(context, R.raw.tmp)
mediaPlayer.start()
【问题讨论】:
-
我很难理解你的问题。我看到你有一个方法
DogHandler来生成名称,但是 MP3 在哪里?您的 Android 项目中的raw中是否有文件dachsund_0到dachsund_10? -
原来如此,它们在原始文件夹中