void playMusic(char *filename, int loop) { if (music != NULL) { Mix_HaltMusic(); Mix_FreeMusic(music); music = NULL; } music = Mix_LoadMUS(getFileLocation(filename)); Mix_PlayMusic(music, (loop) ? -1 : 0); }
/// Execute the algorithm void CatalogDownloadDataFiles::exec() { // Cast a catalog to a catalogInfoService to access downloading functionality. auto catalogInfoService = boost::dynamic_pointer_cast<API::ICatalogInfoService>( API::CatalogManager::Instance().getCatalog(getPropertyValue("Session"))); // Check if the catalog created supports publishing functionality. if (!catalogInfoService) throw std::runtime_error("The catalog that you are using does not support external downloading."); // Used in order to transform the archive path to the user's operating system. CatalogInfo catalogInfo = ConfigService::Instance().getFacility().catalogInfo(); std::vector<int64_t> fileIDs = getProperty("FileIds"); std::vector<std::string> fileNames = getProperty("FileNames"); // Stores the paths to the related files located in the archives (if user has access). // Otherwise, stores the path to the downloaded file. std::vector<std::string> fileLocations; m_prog = 0.0; std::vector<int64_t>::const_iterator fileID = fileIDs.begin(); std::vector<std::string>::const_iterator fileName = fileNames.begin(); // For every file with the given ID. for(; fileID != fileIDs.end(); ++fileID, ++fileName) { m_prog += 0.1; double prog = m_prog / (double(fileIDs.size()) /10 ); progress(prog,"getting location string..."); // The location of the file (on the server) stored in the archives. std::string fileLocation = catalogInfoService->getFileLocation(*fileID); g_log.debug() << "CatalogDownloadDataFiles -> File location before transform is: " << fileLocation << std::endl; // Transform the archive path to the path of the user's operating system. fileLocation = catalogInfo.transformArchivePath(fileLocation); g_log.debug() << "CatalogDownloadDataFiles -> File location after transform is: " << fileLocation << std::endl; // Can we open the file (Hence, have access to the archives?) std::ifstream hasAccessToArchives(fileLocation.c_str()); if(hasAccessToArchives) { g_log.information() << "File (" << *fileName << ") located in archives (" << fileLocation << ")." << std::endl; fileLocations.push_back(fileLocation); } else { g_log.information() << "Unable to open file (" << *fileName << ") from archive. Beginning to download over Internet." << std::endl; progress(prog/2,"getting the url ...."); // Obtain URL for related file to download from net. const std::string url = catalogInfoService->getDownloadURL(*fileID); progress(prog,"downloading over internet..."); const std::string fullPathDownloadedFile = doDownloadandSavetoLocalDrive(url,*fileName); fileLocations.push_back(fullPathDownloadedFile); } } // Set the fileLocations property setProperty("FileLocations",fileLocations); }
static Mix_Chunk *loadSound(char *filename) { return Mix_LoadWAV(getFileLocation(filename)); }