简体   繁体   English

如何获取Raw文件夹中存在的文件的名称

[英]How to obtain name of the file present in Raw folder


I am working on a music player app where I play audio files present in Raw folder. 我正在使用音乐播放器应用程序,在其中播放Raw文件夹中存在的音频文件。
I have 2 files named abc.mp3 and def.mp3 in "raw" folder. 我在“原始”文件夹中有2个名为abc.mp3和def.mp3的文件。
On Click of Button I play abc.mp3 and click on other button I play def.mp3 在单击按钮时,我播放abc.mp3,然后单击其他按钮,我播放def.mp3
I need to display the name of the file I'm playing on a TextView . 我需要显示正在TextView上播放的文件的名称。
When I click on button I need to display a message saying "Playing abc song" on another I need to display "playing def song" How do I get the name of the file present in "raw" folder. 当我单击按钮时,我需要在另一个屏幕上显示一条消息,提示“正在播放abc歌曲”。我需要显示“正在播放def歌曲”。如何获取“ raw”文件夹中文件的名称。
Can anyone help in obtaining the name of mp3 files present in raw folder . 任何人都可以帮助获取原始文件夹中存在的mp3文件的名称。

Here is the code to get all names of files in raw folder. 这是获取原始文件夹中文件所有名称的代码。 Thanks to @Padde 感谢@Padde

ArrayList<String> list = new ArrayList<String>();
Field[] fields = R.raw.class.getFields();
for(Field f : fields)
try {
    list.add(f.getName());
    } catch (IllegalArgumentException e) {
    } catch (IllegalAccessException e) { 
    }

I have modified the answer of @Padde Here 在这里修改了@Padde的答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM