Tôi đang theo dõi tất cả các hướng dẫn tệp mở rộng chính thức, nhưng tôi không thể tìm thấy tệp đó. Tôi không thể truy cập vào tập tin obb chứa tôi cần.Truy cập vào các tệp trong tệp mở rộng obb
Tôi cần 6 tệp âm thanh (80Mb) mà tôi "lưu trữ" (không nén) trong tệp zip và được đổi tên thành 'main.2001.test.expansion.proj.obb' và được lưu trữ trong '/ mnt/sdcard/Android /obb/test.expansion.proj/'
tôi sẽ cố gắng truy cập vào các tập tin
String mainFileName = Helpers.getExpansionAPKFileName(this,true,2001);
if(!Helpers.doesFileExist(this, mainFileName, 27959282L, false))
{
//download
} else {
Log.d("test_file","file exist");
}
ZipResourceFile expansionFile = APKExpansionSupport.getAPKExpansionZipFile(this,2001,2001);
if(expansionFile!=null)
{
ZipEntryRO[] ziro = expansionFile.getAllEntries();
for (ZipEntryRO entry : ziro) {
Log.d("test_files_zip", "fileZip filename: "+entry.getZipFileName());
try{
AssetFileDescriptor ro = entry.getAssetFileDescriptor();
Log.d("test_files_zip", "--fileZip getfiledescriptor.tostring: "+ro.getFileDescriptor().toString());
Log.d("test_files_zip", "--fileZip createinputstring.tostring: "+ro.createInputStream().toString());
AssetFileDescriptor assetFileDescriptor = expansionFile.getAssetFileDescriptor(entry.getZipFileName()+"/audio02.mp3");
if(assetFileDescriptor!=null) {
Log.d("test_files_mp3", "length: "+assetFileDescriptor.getLength()); //checking it exists
}
}catch (IOException e){ Log.e("test_exp","IoExcp: "+e.getMessage()); }
}
}
Trong -> assetFileDescriptor = expansionFile.getAssetFileDescriptor (.....); Tôi đã thử tất cả tôi figuret ra và tìm thấy ở những nơi khác nhau, nhưng tôi đã không thể lấy tập tin. Có cách nào để lấy tệp từ tên của nó nếu nó nằm trong zip không?
Ứng dụng sẽ phát những tệp này theo một thứ tự cụ thể và chúng tôi không muốn giải nén tệp và đặt chúng ở chế độ công khai "".
Đã chỉnh sửa. Trả lời cho bản thân mình
Tìm thấy, đó là một dòng tôi không hiểu khi tôi lần đầu tiên đọc nó hoặc tôi chỉ đơn giản là bỏ lỡ nó.
ZipResourceFile expansionFile = APKExpansionSupport.getAPKExpansionZipFile(this,2001,2001);
if(expansionFile!=null){
FileDescriptor fd = expansionFile.getAssetFileDescriptor("audio_01.mp3");
//or
InputStream is = expansionFile.getInputStream("audio_01.mp3");
}
có thể asnwer này sẽ giúp bạn bằng cách nào đó http://stackoverflow.com/questions/11715855/steps-to-create-apk-expansion-file/11717019#11717019 –
Không, Đó là một trong những nguồn i đã được sử dụng, nhưng không có gì về việc đọc một tập tin bên trong obb. – Jordi
Tôi đã thử 'AssetFileDescriptor fd = expansionFile.getAssetFileDescriptor (zip [0] .mFileName);'. nhưng 'fd' là null. Bạn có thể giúp tôi được không? –