如何从apk扩展文件中播放视频?

时间:2013-03-06 13:25:08

标签: android eclipse

我在Android中创建开发应用程序,其中有大约500 MB的视频用于上传apk扩展文件方法我上传扩展并下载它但现在我无法播放视频http://blogmobile.itude.com/2012/11/22/expanding-your-horizons-using-expansion-files-for-android/我按照这个例子播放视频但是它不能与我合作http://ktakeda47.blogspot.com/2012/04/apk-expansion-files.html我按照此链接进行扩展文件下载。现在请问如何播放扩展文件中的视频Dir =“/ sdcard / Android / obb”?

1 个答案:

答案 0 :(得分:2)

我正在使用以下代码使用APKexpansion lib从obb APKExpansionSupport文件播放mp4:

ZipResourceFile expansionFile = null;
AssetFileDescriptor mAFD= null;
try {
    expansionFile = APKExpansionSupport.getAPKExpansionZipFile(this, 1, 0);
    mAFD = expansionFile.getAssetFileDescriptor(strVideoFile);
} catch (IOException e) {
    e.printStackTrace();
} catch (NullPointerException e) {
    e.printStackTrace();
}
    if (expansionFile==null || mAFD == null){
        Toast.makeText(this, "obb is not here or doesn't contain file: "+strVideoFile, Toast.LENGTH_LONG).show();
        return false;
    }
        mMediaPlayer.setDataSource(mAFD.getFileDescriptor(), mAFD.getStartOffset(), mAFD.getLength());

请记住 - 您必须打包没有任何压缩级别的obb zip存档。这是非常重要的。它必须是没有压缩的zip存档(level = 0) However there is a URI mentioned in APKES docs (speaking of VideoView)但我无法获得如何从APK中获取URIFinally I found how to do it here 因此,要使用URI,您必须像他的示例中那样扩展com.android.vending.expansion.zipfile.APEZProvider并对Manifest进行更改,它应该可以正常工作。