当前位置: 首页>>代码示例>>C++>>正文


C++ AssetLoader::open方法代码示例

本文整理汇总了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;
}
开发者ID:johanekholm,项目名称:hex-game,代码行数:52,代码来源:Sound.cpp

示例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;
}
开发者ID:mickeprag,项目名称:hex-game,代码行数:23,代码来源:ResourceLoader.cpp


注:本文中的AssetLoader::open方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。