I'm trying to play a sound file in SFML but it's not playing. This is the sound (warning: loud volume): http://ift.tt/1J8fyY0. I've used an online converter to convert it to wav (http://ift.tt/1dY82gb) but the sound plays fine in windows so that shouldn't be the problem.
SoundManager.h
#pragma once
#include <SFML\Audio.hpp>
#include <map>
class SoundManager
{
public:
SoundManager();
~SoundManager();
static bool load();
static std::map<std::string, sf::Sound> sound;
};
SoundManager.cpp
#include "SoundManager.h"
#include <SFML\Audio.hpp>
#include <map>
std::map<std::string, sf::Sound> SoundManager::sound = std::map<std::string, sf::Sound>();
SoundManager::SoundManager()
{
}
SoundManager::~SoundManager()
{
}
bool SoundManager::load() {
sf::SoundBuffer laughterBuffer;
if (!laughterBuffer.loadFromFile("data/sound/laughter.wav")) {
return false;
}
sf::Sound laughter;
laughter.setBuffer(laughterBuffer);
SoundManager::sound["laughter"] = laughter;
}
Here I load the sound:
Logger::print("Loading sound...");
if (!SoundManager::load()) {
Logger::error("Failed to load sound! Exiting...");
exit();
}
Logger::print("Sound loaded.");
And I play it like this just before entering the game loop (I've tried calling it from multiple places; none work)
SoundManager::sound["laughter"].play();
When I first tried to import SFML\Audio.hpp it gave me an error about not finding libsndfile-1.dll, so I copy/pasted it into the folder and now it works, but I'm not sure why that happened since I'm linking statically. Could it have something to do with how I am linking to SFML?
sfml-main.lib
sfml-network-s.lib
ws2_32.lib
sfml-audio-s.lib
sndfile.lib
openal32.lib
sfml-window-s.lib
sfml-system-s.lib
opengl32.lib
gdi32.lib
winmm.lib
sfml-graphics-s.lib
glew.lib
freetype.lib
jpeg.lib
Aucun commentaire:
Enregistrer un commentaire