如何从AAssetManager获取std :: basic_istream? [英] How to get std::basic_istream from AAssetManager?
问题描述
我正在使用NDK,需要读取资源媒体文件.因此,据我了解,为了访问资源,我需要使用AAssetManager
,最终我需要获得std::basic_istream
才能使用它.
所以,问题是,如何从AAssetManager
获取std::basic_istream
?
实际上,答案是完全不同的,无论您是压缩资产(例如文本)还是未压缩(默认情况下,Jpeg图像和mp3由打包程序存储).对于这些未压缩的资产,可以使用AAsset_openFileDescriptor()
获取文件描述符,然后按照 如何构造c ++的方法进行操作.来自POSIX文件描述符的fstream吗? .对于压缩资产,您可能会寻找一个(可能与API级别相关的)黑客,该黑客可让您获取操作系统在解压缩资产时为您打开的临时文件的文件描述符(或文件路径). >
I am using NDK and I need to read resource media file. So, as far as I understand in order to access to resources I need to use AAssetManager
, and eventually I need to get std::basic_istream
to work with it.
So, question is, how to get std::basic_istream
from AAssetManager
?
The answer is actually very different whether you have a compressed asset (e.g. text) or uncompressed (by default, Jpeg images and mp3 are stored by the packer). For these uncompressed assets, you can get the file descriptor with AAsset_openFileDescriptor()
, and then follow the ways of How to construct a c++ fstream from a POSIX file descriptor?. For compressed assets, you may look for a (potentially API-level-dependent) hack that will let you get the file descriptor (or file path) to the transient file that the OS opens for you when it unpacks your asset.
这篇关于如何从AAssetManager获取std :: basic_istream?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!