1

我正在尝试从已安装的 Google Play APK 扩展 OBB 文件中的文件加载电影。

mMediaPlayer = new MediaPlayer();

StorageManager storageManager = (StorageManager)mParentActivity.getSystemService(Context.STORAGE_SERVICE);

String obbPath = ExpansionHelper.getExpansionFilePath(mParentActivity);
File movie = new File(storageManager.getMountedObbPath(obbPath), filename);

Log.d(Constants.TAG, "Movie exists is " + movie.exists());

mMediaPlayer.setDataSource(obbPath);

注意:电影存在日志“真”

E/MediaPlayer(27155):错误 (1,-2147483648) 打开文件时出错。卸载媒体播放器(未指定的媒体播放器错误,-2147483648) E/MediaPlayer(27155):在状态 0 中调用停止 E/MediaPlayer(27155):错误 (-38, 0)

如何从 APK OBB 扩展文件(不是 zip 类型)播放电影?

4

2 回答 2

1

我不确定为什么这种方法确实有效,但是如果您从 FileInputStream 提供 FileDescriptor 就像一个魅力!

FileInputStream fis = new FileInputStream(movie);
mMediaPlayer.setDataSource(fis.getFD());
fis.close();
于 2013-07-03T16:23:12.613 回答
0

哦,刚刚看到这个问题是关于非压缩文件的,无论如何这里是压缩版本:

private static void setMediaPlayerDataSourceFromZip(MediaPlayer mediaPlayer,
        String zipFileName, String fileNameInZip) throws IOException,
        FileNotFoundException {
    ZipResourceFile zip = new ZipResourceFile(zipFileName);
    FileInputStream fis = new FileInputStream(zipFileName);
    try {
        FileDescriptor zipfd = fis.getFD();

        ZipEntryRO entry = zipFindFile(zip, fileNameInZip);
        mediaPlayer.setDataSource(zipfd, entry.mOffset,
                entry.mUncompressedLength);
    } finally {
        fis.close();
    }
}

private static ZipEntryRO zipFindFile(ZipResourceFile zip, String fileNameInZip) {
    for (ZipEntryRO entry : zip.getAllEntries()) {
        if (entry.mFileName.equals(fileNameInZip))
            return entry;
    }
    throw new RuntimeException(String.format("File \"%s\"not found in zip", fileNameInZip));
}

用法:

setMediaPlayerDataSourceFromZip(mediaPlayer,
   "/Some/zip/obb/withoutCompression.zip",
   "path/within/zip/mymovie.mp4");
于 2014-07-22T13:46:45.750 回答