简体   繁体   English

如何使用索引直接从raw / res文件夹访问音频文件

[英]How to access the audio files directly from raw/res folder using index

I am trying to develop an small app which will play the all the audio files available there in the raw/res folder using its index. 我正在尝试开发一个小应用程序,它将使用其索引播放raw / res文件夹中可用的所有音频文件。

I am able to play an individual file. 我可以播放单个文件。 In my program I have created three button next previous and pause on the click of next button next song shall be played,on the click of previous button previous song shall be played and on the click of pause button media player should be paused. 在我的程序中,我创建了下一个按钮前面的三个按钮,然后点击下一个按钮暂停下一首歌曲将被播放,点击上一个按钮将播放上一首歌曲,并且在点击暂停按钮时应暂停媒体播放器。

But I am not able to get the audio files by its index. 但我无法通过其索引获取音频文件。

You can get the resource ID with getResources().getIdentifier("FILENAME_WITHOUT_EXTENSION","raw", getPackageName()); 您可以使用getResources()获取资源ID.getIdentifier(“FILENAME_WITHOUT_EXTENSION”,“raw”,getPackageName());

InputStream ins = getResources().openRawResource(getResources().getIdentifier("FILENAME_WITHOUT_EXTENSION","raw", getPackageName())); InputStream ins = getResources()。openRawResource(getResources()。getIdentifier(“FILENAME_WITHOUT_EXTENSION”,“raw”,getPackageName()));

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

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