Beispiel #1
0
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;
}
Beispiel #2
0
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;
}