本文整理汇总了C++中AssetLoader::open方法的典型用法代码示例。如果您正苦于以下问题:C++ AssetLoader::open方法的具体用法?C++ AssetLoader::open怎么用?C++ AssetLoader::open使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AssetLoader
的用法示例。
在下文中一共展示了AssetLoader::open方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: initFile
void Sound::initFile(const std::string &name) {
SLresult result;
std::string filename = name + ".mp3";
// use asset manager to open asset by filename
AssetLoader *loader = AssetLoader::instance();
AAsset *asset = loader->open(filename);
// the asset might not be found
if (NULL == asset) {
LOGI("Asset not found: %s", name.c_str());
return;
}
// open asset as file descriptor
off_t start, length;
int fd = AAsset_openFileDescriptor(asset, &start, &length);
assert(0 <= fd);
AAsset_close(asset);
// configure audio source
SLDataLocator_AndroidFD loc_fd = {SL_DATALOCATOR_ANDROIDFD, fd, start, length};
SLDataFormat_MIME format_mime = {SL_DATAFORMAT_MIME, NULL, SL_CONTAINERTYPE_UNSPECIFIED};
SLDataSource audioSrc = {&loc_fd, &format_mime};
// configure audio sink
SLDataLocator_OutputMix loc_outmix = {SL_DATALOCATOR_OUTPUTMIX, pd->outputMixObject};
SLDataSink audioSnk = {&loc_outmix, NULL};
// create audio player
PrivateImplData::SoundPlayer soundPlayer;
const SLInterfaceID ids[1] = {SL_IID_SEEK};
const SLboolean req[1] = {SL_BOOLEAN_TRUE};
result = (*pd->engineEngine)->CreateAudioPlayer(pd->engineEngine, &soundPlayer.fdPlayerObject, &audioSrc, &audioSnk,
1, ids, req);
assert(SL_RESULT_SUCCESS == result);
// realize the player
result = (*soundPlayer.fdPlayerObject)->Realize(soundPlayer.fdPlayerObject, SL_BOOLEAN_FALSE);
assert(SL_RESULT_SUCCESS == result);
// get the play interface
result = (*soundPlayer.fdPlayerObject)->GetInterface(soundPlayer.fdPlayerObject, SL_IID_PLAY, &soundPlayer.fdPlayerPlay);
assert(SL_RESULT_SUCCESS == result);
// get the seek interface
result = (*soundPlayer.fdPlayerObject)->GetInterface(soundPlayer.fdPlayerObject, SL_IID_SEEK, &soundPlayer.fdPlayerSeek);
assert(SL_RESULT_SUCCESS == result);
pd->soundPlayers[name] = soundPlayer;
}
示例2: loadLuaScript
std::string ResourceLoader::loadLuaScript(const std::string &scriptname) {
const std::string &filename = scriptname + ".lua";
AssetLoader *loader = AssetLoader::instance();
AAsset *asset = loader->open(filename);
// the asset might not be found
if (NULL == asset) {
DEBUGLOG("Asset not found: %s", filename.c_str());
return NULL;
}
size_t length = AAsset_getLength(asset);
const char *buffer = (char *)AAsset_getBuffer(asset);
std::string script(buffer, length);
if (buffer = NULL) {
DEBUGLOG("Buffer is empty");
}
AAsset_close(asset);
return script;
}