0
我有一個140 MB的ZIP文件,其中包含約4萬個MP3文件。我使用下面的代碼打ZIP文件中某些文件不解壓它:爲什麼ZipEntry無法在果凍豆中工作
String fullPath = Environment.getExternalStorageDirectory().getPath() + "_audio_.mp3";
String path = Environment.getExternalStorageDirectory().getPath() + "mySoundFolder";
try {
ZipFile zip = new ZipFile(path + "myFile.zip");
Enumeration zipEntries = zip.entries();
ZipEntry entry = zip.getEntry("myFile" + "/" + currentWord + ".mp3");
if (entry != null) {
Log.i(MAIN_TAG, "entry found: " + entry.getName());
InputStream in = zip.getInputStream(entry);
File f = new File(fullPath);
FileOutputStream out = new FileOutputStream(f);
IOUtils.copy(in, out);
byte buffer[] = new byte[4096];
int read;
while ((read = in.read(buffer)) != -1)
{
out.write(buffer, 0, read);
}
if (f.exists())
{
Log.i(MAIN_TAG,"Audio file found!");
final MediaPlayer mp = new MediaPlayer();
mp.setDataSource(fullPath);
mp.prepare();
mp.setOnBufferingUpdateListener(null);
mp.setLooping(false);
mp.setOnPreparedListener(new OnPreparedListener()
{ public void onPrepared(MediaPlayer arg0)
{
mp.start();
Log.i(MAIN_TAG,"Pronunciation finished!");
}});
}
else
{
Log.i(MAIN_TAG,"File doesn't exist!!");
}
}
else {
// no such entry in the zip
Log.i(MAIN_TAG, "no such entry in the zip");
}
}
catch (IOException e) {
e.printStackTrace();
Log.i(MAIN_TAG,"IOException reading zip file");
}
}
有兩個與此代碼奇怪的事情:
- 它完美的作品在
Android 2.2
但Android 4.0.3
失敗。在2.2
,它發現並播放MP3文件,但我認爲它在4.0.3
,它一直說它無法找到ZIP文件中的條目("no such entry in the zip"
)。 - 如果我將MP3文件的數量減少到大約100個文件,則在
Android 4.0.3
中,它會查找並播放所選的MP3文件。
你們能幫我找出問題所在嗎?
非常感謝。
此代碼在非android環境(例如:PC)上工作正常嗎?即'zip.getEntry(「myFile」+「/」+ currentWord +「.mp3」);'在PC上返回一個條目而不是null? – SrikanthLingala
我不知道,因爲我沒有機會這樣測試。但請注意,此問題僅在「Android 4x」中出現,並且包含超過40k條目的zip文件。 –