微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

android – 从APK扩展文件中读取内容(来自obb文件)

我已经实现了APK扩展文件下载服务,全部来自http://developer.android.com/google/play/expansion-files.html

我可以下载APK扩展文件,我可以使用下面的代码看到该文件

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();
    }

我的obb有文件test.mp4和我的代码Log.e(“”,“”zip [0] .mFileName);打印test.mp4.

我的fd是null.为什么它为空?我试图解决但未能解决.

我只是无法读取obb文件中的任何文件..

没有回答Accessing to files inside obb expansion file暗示想法,但它对我不起作用.

Steps to create APK expansion file告诉来自obb的解压缩内容,然后读取它.它可靠而且好吗?

帮我!!需要最佳实践的意见.谢谢

编辑:

我的日志

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

解决方法:

我用谷歌搜索,发现我们必须制作.zip,其中0%(无压缩)在http://developer.android.com/google/play/expansion-files.html中提到

提示:如果要将媒体文件打包为ZIP,则可以对具有偏移和长度控件的文件(例如MediaPlayer.setDataSource()和SoundPool.load())使用媒体播放调用,而无需解压缩ZIP.为了使其正常工作,在创建ZIP包时,不得对媒体文件执行额外压缩.例如,使用zip工具时,应使用-n选项指定不应压缩的文件后缀:
zip -n .mp4; .ogg main_expansion media_files

或者如何使用winrar制作0%压缩zip?

 

这里看压缩方法

mac中0%压缩zip

Create zip without compression on OS X from Terminal:
zip -r0 zipfilename.zip files-to-zip

所以我们应该在Play商店上传这个zip.

所以你不需要使用ZipHelper.java

只是简单地使用

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();
            }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐