阅读从APK扩展文件内容(从OBB文件) [英] Read content from APK expansion file (from obb file)
问题描述
我已经实现APK扩展文件下载服务,并全部由的http://开发商.android.com /谷歌/播放/膨胀files.html
我可以下载APK扩展文件,我可以使用下面code看到文件
尝试{
子presourceFile expansionFile = APKExpansionSupport
.getAPKExpansionZipFile(此,3,0);
ZipEntryRO []拉链= expansionFile.getAllEntries();
Log.e(,+拉链[0] .mFile.getAbsolutePath());
Log.e(,+拉链[0] .mFileName);
Log.e(,+拉链[0] .mZipFileName);
Log.e(,+拉链[0] .mCom pressedLength);
AssetFileDescriptor FD = expansionFile
.getAssetFileDescriptor(ZIP [0] .mFileName);
如果(FD = NULL和放大器;!&安培;!fd.getFileDescriptor()= NULL){
MediaPlayer的熔点为新的MediaPlayer();
mp.setDataSource(fd.getFileDescriptor());
mp.start();
} 其他 {
Log.e(,FD或fd.getFileDescriptor()为null);
}
}赶上(IOException异常E){
e.printStackTrace();
}
我的OBB是有文件 test.mp4
和我的code Log.e(,+拉链[0] .mFileName);
打印 test.mp4
我的 FD
是空
。为什么空
?我想解决但未能解决的问题。
我只是无法读取里面的OBB文件中的任何文件。
未答复的<一个href="http://stackoverflow.com/questions/12635069/accessing-to-files-inside-obb-expansion-file">Accessing里面OBB扩展文件中的文件暗示的想法,但它并没有为我工作。
<一个href="http://stackoverflow.com/questions/11715855/steps-to-create-apk-expansion-file/11717019#11717019">Steps创建APK扩展文件告诉从OBB解压内容,然后阅读。它是可靠的,好不好?
帮助我!需要最佳实践opnion。谢谢
编辑:
我的日志
十月3号至1日:36:40.848:E /(27836):拉链[0] .isUncom pressed():假
10月3号至一日:36:40.848:E /(27836):mFile.getAbsolutePath():/storage/sdcard0/Android/obb/smart.trigger/main.3.smart.trigger.obb
10月3号至一日:36:40.848:E /(27836):mFileName:test.mp4
10月3号至一日:36:40.848:E /(27836):mZipFileName:/storage/sdcard0/Android/obb/smart.trigger/main.3.smart.trigger.obb
10月3号至一日:36:40.848:E /(27836):MCOM pressedLength:21657598
我用Google搜索,发现我们shold不得不作出的.zip与 0%(没有COM pression)
即提及 http://developer.android.com/google /play/expansion-files.html
提示:如果你在打包的媒体文件成ZIP,你可以使用这些文件的媒体播放与通话偏移量和长度的控制(如MediaPlayer.setDataSource()和SoundPool.load() )无需解压您的邮递。为了这个工作,你不能创建ZIP包时,执行上的媒体文件的其他COM pression。例如,使用压缩工具时,你应该使用-n选项来指定文件后缀不应该是COM pressed:
拉链-n .MP4; .OGG main_expansion media_files
或如何用winrar制作0%COM pression拉链?
在这里看到的COM pression方法
所以我们应该要上传这个压缩在游戏商店。
,所以你并不需要使用 ZipHelper.java
只是简单地使用
子presourceFile expansionFile = NULL;
尝试 {
expansionFile = APKExpansionSupport.getAPKExpansionZipFile(getApplicationContext(),3,0);
AssetFileDescriptor FD = expansionFile.getAssetFileDescriptor(test.mp4);
MediaPlayer的MPLAYER =新的MediaPlayer();
mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mPlayer.setDataSource(fd.getFileDescriptor(),fd.getStartOffset(),fd.getLength());
MPLAYER prepare()。
mPlayer.start();
}赶上(IOException异常E){
// TODO自动生成的catch块
e.printStackTrace();
}
I have implemented APK expansion file download service and all from http://developer.android.com/google/play/expansion-files.html
I can download APK expansion file and I can see that file using below code
try {
ZipResourceFile expansionFile = APKExpansionSupport
.getAPKExpansionZipFile(this, 3, 0);
ZipEntryRO[] zip = expansionFile.getAllEntries();
Log.e("", "" + zip[0].mFile.getAbsolutePath());
Log.e("", "" + zip[0].mFileName);
Log.e("", "" + zip[0].mZipFileName);
Log.e("", "" + zip[0].mCompressedLength);
AssetFileDescriptor fd = expansionFile
.getAssetFileDescriptor(zip[0].mFileName);
if (fd != null && fd.getFileDescriptor() != null) {
MediaPlayer mp = new MediaPlayer();
mp.setDataSource(fd.getFileDescriptor());
mp.start();
} else {
Log.e("", "fd or fd.getFileDescriptor() is null");
}
} catch (IOException e) {
e.printStackTrace();
}
My obb is having file test.mp4
and my code Log.e("", "" + zip[0].mFileName);
prints test.mp4.
My fd
is null
. Why is it null
? I am trying to resolve but failed to resolve.
I just can not read any file inside obb file..
Unanswered Accessing to files inside obb expansion file suggesting idea but it does not work for me.
Steps to create APK expansion file tells unzip content from obb and then read it. is it reliable and good?
Help me!! Need opnion of best practice. Thanks
EDIT :
My log
03-01 10:36:40.848: E/(27836): zip[0].isUncompressed() : false
03-01 10:36:40.848: E/(27836): mFile.getAbsolutePath() : /storage/sdcard0/Android/obb/smart.trigger/main.3.smart.trigger.obb
03-01 10:36:40.848: E/(27836): mFileName : test.mp4
03-01 10:36:40.848: E/(27836): mZipFileName : /storage/sdcard0/Android/obb/smart.trigger/main.3.smart.trigger.obb
03-01 10:36:40.848: E/(27836): mCompressedLength : 21657598
i have googled and found that we shold have to make .zip with 0% (No compression)
that is mention in http://developer.android.com/google/play/expansion-files.html
Tip: If you're packaging media files into a ZIP, you can use media playback calls on the files with offset and length controls (such as MediaPlayer.setDataSource() and SoundPool.load()) without the need to unpack your ZIP. In order for this to work, you must not perform additional compression on the media files when creating the ZIP packages. For example, when using the zip tool, you should use the -n option to specify the file suffixes that should not be compressed:
zip -n .mp4;.ogg main_expansion media_files
OR How to make 0% compression zip using winrar?
here see the compression method
so we should have to upload this zip in play store.
so you not need to use ZipHelper.java
just simply use
ZipResourceFile expansionFile=null;
try {
expansionFile = APKExpansionSupport.getAPKExpansionZipFile(getApplicationContext(),3,0);
AssetFileDescriptor fd = expansionFile.getAssetFileDescriptor("test.mp4");
MediaPlayer mPlayer = new MediaPlayer();
mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mPlayer.setDataSource(fd.getFileDescriptor(),fd.getStartOffset(),fd.getLength());
mPlayer.prepare();
mPlayer.start();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
这篇关于阅读从APK扩展文件内容(从OBB文件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!