Ejemplo n.º 1
0
void SimpleAudioEngine::unloadEffect(const char* pszFilePath)
{
	string strFilePath = fullPathFromRelativePath(pszFilePath);
	unsigned int nSoundId = _Hash(strFilePath.c_str());
	CCAudioOut*& pPlayer = s_List[nSoundId];
	pPlayer->Stop();
}
Ejemplo n.º 2
0
unsigned char* FileUtils::getFileData(const char* pszFileName, const char* pszMode, unsigned long * pSize)
{
    unsigned char * pBuffer = NULL;

    do 
    {
        if (strlen(s_ZipFilePath) != 0)
        {
            // if specify the zip file,load from it first
            pBuffer = getFileDataFromZip(s_ZipFilePath, pszFileName, pSize);
            BREAK_IF(pBuffer);
        }
        
        // read the file from hardware
        char fullPath[EOS_FILE_MAX_PATH] = {0};
        fullPathFromRelativePath(pszFileName, fullPath);

        BREAK_IF(strlen(fullPath) <= 0);
        FILE *fp = fopen(fullPath, pszMode);
        BREAK_IF(!fp);

        fseek(fp,0,SEEK_END);
        *pSize = ftell(fp);
        fseek(fp,0,SEEK_SET);
        pBuffer = new unsigned char[*pSize];
        fread(pBuffer,sizeof(unsigned char), *pSize,fp);
        fclose(fp);
    } while (0);

    return pBuffer;
}
Ejemplo n.º 3
0
void SimpleAudioEngine::preloadEffect(const char* pszFilePath)
{
	int nRet = 0;
	CCAudioOut* pEffectPlayer = NULL;
	do
	{
		BREAK_IF(! pszFilePath);

		string strFilePath = fullPathFromRelativePath(pszFilePath);

		nRet = _Hash(strFilePath.c_str());

		BREAK_IF(s_List.end() != s_List.find(nRet));

		//AppLog("not find effect, create it...");
		if (s_List.size() >= 64)
		{
			// get the first effect, and remove it form list
			//AppLog("effect preload more than 64, delete the first effect");
			pEffectPlayer = s_List.begin()->second;
			pEffectPlayer->Finalize();
			s_List.erase(s_List.begin()->first);
		}
		if (pEffectPlayer == NULL)
			pEffectPlayer = new CCAudioOut;
		pEffectPlayer->Initialize(strFilePath.c_str());

		s_List.insert(Effect(nRet, pEffectPlayer));

	} while (0);
}
Ejemplo n.º 4
0
const char *CCFileUtils::fullPathFromRelativeFile(const char *pszFilename, const char *pszRelativeFile)
{
	std::string relativeFile = fullPathFromRelativePath(pszRelativeFile);
	NSString *pRet = new NSString();
	pRet->autorelease();
	pRet->m_sString = relativeFile.substr(0, relativeFile.rfind('/')+1);
	pRet->m_sString += pszFilename;
	return pRet->m_sString.c_str();
}
Ejemplo n.º 5
0
static bool openMediaPlayer(Player*& pPlayer, const char* pszFilePath)
{
	bool bRet = false;
	result r = E_FAILURE;

	do
	{
		closeMediaPlayer(pPlayer);

		if (pPlayer == NULL)
		{
			pPlayer = new Player();
			r = pPlayer->Construct(s_playerListener, null);
			if (IsFailed(r))
			{
				AppLog("player construct fails, pszFilePath = %s", pszFilePath);
				delete pPlayer;
				pPlayer = NULL;
				break;
			}
		}

		string strFilePath = fullPathFromRelativePath(pszFilePath);
		// OpenFile must use synchronous param, for after that it will playing.
		r = pPlayer->OpenFile(strFilePath.c_str(), false);
		if (IsFailed(r))
		{
			AppLog("Open (%s) fails\n", strFilePath.c_str());
			delete pPlayer;
			pPlayer = NULL;
			break;
		}
		else
		{
			bRet = true;
		}
	}
	while (0);

	SimpleAudioEngine::sharedEngine()->setBackgroundMusicVolume(s_fBackgroundMusicVolume);

	return bRet;
}
Ejemplo n.º 6
0
bool FileUtils::isFileExisted(const char* pFilePath)
{
    bool bRet = false;

    if (strlen(s_ZipFilePath) != 0)
    {
        // if have set the zip file path,find the resource in the zip file
        unzFile pZipFile = unzOpen(s_ZipFilePath);
        do 
        {
            BREAK_IF(!pZipFile);

            Int32 nPos = unzLocateFile(pZipFile, pFilePath, 1);
            BREAK_IF(nPos != UNZ_OK);

            bRet = true;
            unzClose(pZipFile);
        } while (0);
    }
    else
    {
        char fullPath[EOS_FILE_MAX_PATH];
        fullPathFromRelativePath(pFilePath, fullPath);

        if (strlen(fullPath) > 0)
        {
            TUChar FilePath[EOS_FILE_MAX_PATH] = {0};
            TUString::StrGBToUnicode(FilePath, (const Char *) fullPath);

            // find in the hardware
            if (EOS_IsFileExist(FilePath))
            {
                bRet = true;
            }
        }
    }

    return bRet;
}
Ejemplo n.º 7
0
// for sound effects
unsigned int SimpleAudioEngine::playEffect(const char* pszFilePath, bool bLoop/* = false*/)
{
	result r = E_FAILURE;
	string strFilePath = fullPathFromRelativePath(pszFilePath);
	unsigned int nRet = _Hash(strFilePath.c_str());

	preloadEffect(pszFilePath);

	EffectList::iterator p = s_List.find(nRet);
	if (p != s_List.end())
	{
		p->second->SetVolume((int) (s_fEffectsVolume * 99));
		int volume = p->second->GetVolume();

    	if (s_fEffectsVolume > 0.0f && volume == 0)
    	{
    		p->second->SetVolume(1);
    	}

	    if (AUDIOOUT_STATE_PLAYING == p->second->GetState())
		{
            return nRet; // Stop waste a lot of time, so just return.
	    	//r = p->second->Stop();
		}

	    if (s_fEffectsVolume > 0.0f)
	    {
	    	r = p->second->Play(bLoop);
	    }

    	if (IsFailed(r))
    	{
    		AppLog("play effect fails, error code = %d", r);
    	}
	}
	return nRet;
}
Ejemplo n.º 8
0
const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath)
{
    ccResolutionType ignore;
    return fullPathFromRelativePath(pszRelativePath, &ignore);
}