/// Play from memory. bool CMusicChannelFMod::playSync(const std::string &filepath, bool loop) { CIFile ifile; ifile.allowBNPCacheFileOnOpen(false); ifile.setCacheFileOnOpen(false); ifile.open(filepath); // try to load the music in memory uint32 fs = ifile.getFileSize(); if (!fs) { nlwarning("NLSOUND FMod Driver: Empty music file"); return false; } // read Buffer nlassert(!_MusicBuffer); _MusicBuffer = new uint8[fs]; try { ifile.serialBuffer(_MusicBuffer, fs); } catch (...) { nlwarning("NLSOUND FMod Driver: Error while reading music file"); delete[] _MusicBuffer; _MusicBuffer = NULL; return false; } // open FMOD stream _MusicStream = FSOUND_Stream_Open((const char*)_MusicBuffer, FSOUND_2D | FSOUND_LOADMEMORY | (loop ? FSOUND_LOOP_NORMAL : FSOUND_LOOP_OFF), 0, fs); if (!_MusicStream) { nlwarning("NLSOUND FMod Driver: Error while creating the FMOD stream for music file"); delete[] _MusicBuffer; _MusicBuffer = NULL; return false; } if (!playStream()) { nlwarning("NLSOUND FMod Driver: Error While trying to play sync music file"); FSOUND_Stream_Close(_MusicStream); _MusicStream = NULL; delete[] _MusicBuffer; _MusicBuffer = NULL; return false; } return true; }
// *************************************************************************** bool CInstanceGroupUser::init (const std::string &instanceGroup, bool async) { // Create a file CIFile file; if(async) { file.setAsyncLoading(true); file.setCacheFileOnOpen(true); } std::string path = CPath::lookup (instanceGroup, false); if (!path.empty() && file.open (path)) { // Serialize this class try { // Read the class _InstanceGroup.serial (file); } catch (const EStream& e) { // Avoid visual warning EStream ee=e; // Serial problem return false; } } else { // Failed. return false; } // Ok return true; }