简体   繁体   English

如何使用循环从资产文件夹加载音频文件?

[英]How can we load audio files from asset folder by using a loop?

In my app, i have a image gallery and while showing each image,an audio should play.This gallery contains more than 100 images.And i placed all my audio files in "raw" folder and the audio filename starts with the position of image.like 1.mp3,2.mp3 etc. 在我的应用中,我有一个图片库,并且在显示每张图片时,应该播放一个音频。该图片库包含100多个图片。我将所有音频文件都放在“原始”文件夹中,音频文件名以图片位置开头。例如1.mp3,2.mp3等。

How can i play this audio dynamically .ie if the gallery is showing 10 th image,then 10.mp3 should play. 我如何动态播放此音频。即,如果画廊正在显示第10张图像,则应播放10.mp3。

Thanks in advance. 提前致谢。

You should define two Integer Arrays , one for your Gallery Images and the Second for your SoundBoard 您应该定义两个Integer Array,一个用于Gallery Images,另一个用于SoundBoard。

Integer[] gallery={R.drawable.first,R.drawable.second,.........etc.};

Integer[] soundBoard={R.raw.first,R.raw.second,.....etc};

The Index you use to show the Gallery Image should be used in the SoundBoard to play the sound using the MediaPlayer class and its Static method create() and play() for ever looping set the looping(true); 用于显示图库图像的索引应在SoundBoard中使用MediaPlayer类及其静态方法create()和play()进行循环播放,以播放声音。

You can always stop when a new image is displayed and play another sound. 当显示新图像时,您始终可以停止并播放其他声音。

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

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