【问题标题】:How to play mp3 files in raw folder with different language?如何以不同语言播放原始文件夹中的 mp3 文件?
【发布时间】:2021-08-23 17:00:17
【问题描述】:

我在 raw 文件夹中有一些 mp3 文件,我将它们作为资源路径(例如 R.raw.music)存储在 Room 数据库中,并且我本地化了 raw 文件夹。我想从选定的语言中获取本地化的 mp3 文件。这是我获得本地化字符串的方法

fun getLocaleStringResource(requestedLocale:Locale,resId:Int,context: Context) :String{
val result:String
val config = Configuration(context.resources.configuration)
config.setLocale(requestedLocale)
result= context.createConfigurationContext(config).getText(resId).toString()
return result}

有没有办法以某种语言获取原始文件?

【问题讨论】:

    标签: android android-studio kotlin android-mediaplayer android-resources


    【解决方案1】:
    1. 为不同语言创建文件夹
    2. 保存同名的音频文件
    3. 使用媒体播放器播放

    MediaPlayer p1=new MediaPlayer(this,R.raw.sample)

    将根据所选语言播放音频

    【讨论】:

    • 感谢您的评论,但我正在使用 Room 库从原始来源获取数据。对不起,我忘了提。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多