编辑编码:
我正在为Android开发一个字典应用程序.我一直在成功地让应用程序发出每个单词的意思.这是代码:
btnPronounce.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//Log.i(MAIN_TAG,"Start pronounciation ...");
btnPronounce.setEnabled(false);
String currentWord = edWord.getText().toString().toLowerCase();
try {
ZipFile zip = new ZipFile("/sdcard/app_folder/sound/zip_test.zip");
ZipEntry entry = zip.getEntry(currentWord);
if (entry != null) {
InputStream in = zip.getInputStream(entry);
// see Note #3.
File tempFile = File.createTempFile("_AUDIO_", ".wav");
FileOutputStream out = new FileOutputStream(tempFile);
IOUtils.copy(in, out);
// do something with tempFile (like play it)
File f = tempFile;
try {
if (f.exists())
{
Log.i(MAIN_TAG,"Audio file found!");
MediaPlayer mp = new MediaPlayer();
mp.prepare();
mp.setLooping(false);
mp.start();
while (mp.getCurrentPosition() < mp.getDuration());
mp.stop();
mp.release();
Log.i(MAIN_TAG,"Pronounciation finished!");
}
else
{
Log.i(MAIN_TAG,"File doesn't exist!!");
}
}
catch (IOException e)
{
Log.i(MAIN_TAG,e.toString());
}
btnPronounce.setEnabled(true); }
else {
// no such entry in the zip
}
} catch (IOException e) {
// handle your exception cases...
e.printStackTrace();
}
}
});
但问题是一个文件夹中的WAV文件太多,所有这些文件都被Android设备视为音乐文件.因此,索引此类文件需要很长时间.此外,索引和用户浏览有时会迫使应用程序崩溃.
因此,我只是想知道以下是否可以通过编程方式完成:
> Android MediaPlayer可以播放压缩或包装在单个文件中的WAV / MP3文件吗?我的意思是我想压缩或包装音频文件(或做类似的事情),以便它们作为单个文件出现在Android设备上,但MediaPlayer仍然可以播放内部的每个单独的WAV文件.
>如果以上情况不可能,你们可以建议解决问题吗?
编辑:
有没有其他方法/解决方案允许将音频文件简单地放入一个大文件(图像,zip或类似…),然后让MediaPlayer读取其中的单个文件?
非常感谢你.