title: sf::Music plays but not sf::Sound? Why?
body: <p>I am learning the SFML library in C++. I have been trying to implement an efficient method of organizing audio in my game by making an Audio class that contains two separate std::map for the music (sf::Music) and the sound (sf::Sound). However, when I run the program, only the music is able to play but not the sound effects. I believe the sound does load fine since it does not throw the error message. Here is my code and info. (Possibly give tips on my code as well since I am new :D )
  Thanks in advance</p>
  
  <p>VS2012, SFML 2.1</p>
  
  <p><strong>SFML_Snake.h</strong> (Game header file)</p>
  
  <pre><code>#pragma once
  #ifndef GUARD_SFML_SNAKE
  #define GUARD_SFML_SNAKE
  
  #include "SFML/Audio.hpp"
  #include "SFML/Graphics.hpp"
  #include "Snake.h"
  #include "Apple.h"
  #include "Audio.h"
  #include &lt;iostream&gt;
  
  class SFML_Snake{
  public:
      SFML_Snake();
      void run();
  private:
      void checkBoundary(Snake);
      void checkApple(Snake&amp;, Apple&amp;, Audio&amp; );
      std::vector&lt;sf::RectangleShape&gt; loadGrid();
  private:
      bool processEvents();
      void update(Audio&amp;);
      void render(std::vector&lt;sf::RectangleShape&gt;&amp;);
  
  public:
      sf::RenderWindow window;
      sf::Text textCount;
      Snake snake;
      Apple apple;
  };
  
  int main(){
      SFML_Snake start;
      start.run();
  }
  #endif
  </code></pre>
  
  <p><strong>SFML_Snake.cpp</strong> (Game source file)</p>
  
  <pre><code>/*Import statements*/
  #include &lt;SFML/Graphics.hpp&gt;
  #include &lt;SFML/Audio.hpp&gt;
  #include &lt;SFML/Window.hpp&gt;
  #include &lt;SFML/System.hpp&gt;
  #include "Snake.h"
  #include "variables.h"
  #include "Apple.h"
  #include "Audio.h"
  #include "SFML_Snake.h"
  #include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;string&gt;
  #include &lt;array&gt;
  #include &lt;map&gt;
  #include &lt;memory&gt;
  
  
  SFML_Snake::SFML_Snake():
  window(sf::VideoMode(windowWidth, windowHeight), "SFML Application" ),
  snake(Snake()), apple(Apple(0,0)), textCount(sf::Text())
  {
      window.setFramerateLimit(FRAMERATE);
  }
  
  
  
  void SFML_Snake::checkBoundary(Snake s){
      for (int z = dots; z &gt; 0; z--){
          if ((s.x[0] == s.x[z]) &amp;&amp; (s.y[0] == s.y[z]))
              inGame = false;
      }
      if (s.y[0] &gt;= windowHeight)
          inGame = false;
      if (s.y[0] &lt; dotSize)
          inGame = false;
      if (s.x[0] &gt;= windowWidth)
          inGame = false;
      if (s.x[0] &lt; dotSize)
          inGame = false;
  }
  
  void SFML_Snake::checkApple(Snake&amp; mA, Apple&amp; mB, Audio&amp; audios){
      if ((mA.x[0] == mB.x()) &amp;&amp; (mA.y[0] == mB.y())){
          audios.getSound("eating").play();
          dots += dotInterval;
          points++;
          if(DEBUG)
          std::cout&lt;&lt; points &lt;&lt; std::endl;
          textCount.setString(std::string("points: ") + std::to_string(points));
          mB.locateApple();
          for(int i = mA.draw().size() - 1; i &gt;= 0; i--){
              while (((mA.x[0] == mB.x()) &amp;&amp; (mA.y[0] == mB.y())) 
                  || (0 == mB.x()) 
                  || (0 == mB.y()) 
                  || (windowWidth - dotSize/2 == mB.x()) 
                  || (windowHeight - dotSize/2 == mB.y())) 
              {
                  mB.locateApple();
              }
          }
      }
  }
  
  bool SFML_Snake::processEvents(){
      sf::Event event;
      while (window.pollEvent(event)){
              if (event.type == sf::Event::Closed)
                  window.close();
          }
      if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Escape)) {
          return true;
      }
      snake.input();
      return false;
  }
  void SFML_Snake::update(Audio&amp; audios){
          snake.checkReals();
          snake.moveUpdate();
          audios.getSound("moving").play();
          checkApple(snake, apple, audios);
          checkBoundary(snake);
  }
  void SFML_Snake::render(std::vector&lt;sf::RectangleShape&gt;&amp; grid){
  
          std::vector&lt;sf::RectangleShape&gt; shapearray = snake.draw();
          for (int i = shapearray.size() - 1; i &gt;= 0; i--){
              window.draw(shapearray[i]);
          }
          window.draw(apple.draw());
          for(int i = grid.size()-1; i&gt;=0; i--){
              window.draw(grid[i]);
          }
          window.draw(textCount);
          window.display();
  }
  std::vector&lt;sf::RectangleShape&gt; SFML_Snake::loadGrid(){
      std::vector&lt;sf::RectangleShape&gt; grid;
      for(int k= dotSize/2; k&lt;=windowHeight+dotSize/2; k+=dotSize){
              sf::RectangleShape line;
              line.setPosition(0, k-dotSize);
              line.setSize(sf::Vector2f(windowWidth, 1));
              line.setFillColor(sf::Color::Black);
              if(k==dotSize/2 || k == windowHeight + dotSize/2){
                  line.setSize(sf::Vector2f(windowWidth, dotSize));
              }
              grid.push_back(line);
          }
      for(int i = dotSize/2; i&lt;=windowWidth+dotSize/2; i+=dotSize){
  
          sf::RectangleShape line;
          line.setPosition(i-dotSize, 0);
          line.setSize(sf::Vector2f(1, windowHeight));
          line.setFillColor(sf::Color::Black);
          if(i==dotSize/2 || i == windowWidth+dotSize/2){
              line.setSize(sf::Vector2f(dotSize, windowHeight));
          }
          grid.push_back(line);
  
      }
      return grid;
  
  }
  
  void SFML_Snake::run(){
      /*Initialize the objects*/
  
      std::vector&lt;sf::RectangleShape&gt; grid = loadGrid();
      if(!DEBUG)
          std::cout&lt;&lt;"DEBUG MODE: OFF" &lt;&lt;std::endl;
      Audio&amp; audios = Audio();
      apple.locateApple();
  
      /*Load the audio*/
  
      audios.getMusic("backgroundMusic").setVolume(10);
      audios.getMusic("backgroundMusic").setLoop(true);
      audios.getMusic("backgroundMusic").setVolume(25);
  
      /*Load the font*/
      sf::Font font;
      if (!(font.loadFromFile("arial.ttf")))
          if(DEBUG)
              std::cout &lt;&lt; "Error loading fonts" &lt;&lt; std::endl;
      /*Create the text*/
      textCount.setFont(font);
      textCount.setString(std::string("points: ") + std::to_string(points));
      textCount.setColor(sf::Color::Red);
      textCount.setCharacterSize(20);
      textCount.setPosition(windowWidth / 2 - (textCount.getString().getSize()*(textCount.getCharacterSize() / 5)), textCount.getCharacterSize() - 10);
      textCount.setStyle(sf::Text::Bold);
      window.draw(textCount);
  
      /*MAIN GAME LOOP*/
      counterTick = 1;
  
      audios.getSound("begin").play();
      audios.getMusic("backgroundMusic").play();
      while (inGame &amp;&amp; !pause)
      {
          std::string counter = std::to_string(counterTick);
          if(DEBUG)
              std::cout &lt;&lt; "Tick: " + counter &lt;&lt; std::endl;
  
          window.clear(sf::Color::White);
          if(processEvents()){
              break;
          }
          update(audios);
          render(grid);
          snake.secInput = false;
          counterTick++;
      }
      audios.getSound("losing").play();
      audios.getMusic("backgroundMusic").stop();
      std::system("PAUSE");//bad practice, debuggin purposes
  }
  </code></pre>
  
  <p><strong>Audio.h</strong></p>
  
  <pre><code>#pragma once
  #ifndef GUARD_AUDIO_H
  #define GUARD_AUDIO_H
  #include "variables.h"
  #include "SFML\Graphics.hpp"
  #include "SFML\Audio.hpp"
  #include &lt;memory&gt;
  
  struct Audio{
      std::map&lt;std::string, sf::Sound&gt; sounds;
      std::map&lt;std::string, std::unique_ptr&lt;sf::Music&gt;&gt; musics;
      //std::map&lt;std::string, sf::Sound&gt; sounds;
      //std::map&lt;std::string, sf::Music&gt; musics;
  
      Audio();
  
      void Audio::addSound(sf::Sound&amp;, sf::SoundBuffer&amp; , const std::string&amp;);
  
      void Audio::addSound(sf::Sound&amp;, const std::string&amp;);
  
      void Audio::addMusic(const std::string&amp;, std::unique_ptr&lt;sf::Music&gt; );
  
      sf::Sound &amp;Audio::getSound(std::string);
  
      sf::Music &amp;Audio::getMusic(std::string);
  
      void Audio::loadAudio();
  };
  
  #endif//GUARD_AUDIO_H
  </code></pre>
  
  <p><strong>Audio.cpp</strong></p>
  
  <pre><code>#include "Audio.h"
  #include &lt;iostream&gt;
      Audio::Audio(){
          loadAudio();
      }
      void Audio::addSound(sf::Sound&amp; s, sf::SoundBuffer&amp; sb, const std::string &amp;key){
          s.setBuffer(sb);
          sounds.insert(std::pair&lt;std::string, sf::Sound&gt;(key, std::move(s)));
      }
      void Audio::addSound(sf::Sound&amp; s, const std::string &amp;key){
          sounds.insert(std::pair&lt;std::string, sf::Sound&gt;(key, s));
      }
      void Audio::addMusic(const std::string &amp;key, std::unique_ptr&lt;sf::Music&gt; value){
          musics.insert(std::pair&lt;std::string, std::unique_ptr&lt;sf::Music&gt; &gt;(key, std::move(value)));
      }
      sf::Sound &amp;Audio::getSound(std::string key){
          return sounds.at(key);
      }
      sf::Music &amp;Audio::getMusic(std::string key){
          return *musics.at(key);
      }
      void Audio::loadAudio(){
  
      //sf::Music backgroundMusic;
      sf::Sound s_eating;
      sf::SoundBuffer sb_eating;
      sf::Sound s_moving;
      sf::SoundBuffer sb_moving;
      sf::Sound s_losing;
      sf::SoundBuffer sb_losing;
      sf::Sound s_begin;
      sf::SoundBuffer sb_begin;
  
      auto backgroundMusic = std::unique_ptr&lt;sf::Music&gt;(new sf::Music());
  
      if (!backgroundMusic-&gt;openFromFile("backgroundmusic.wav"))
          if(DEBUG)
              std::cerr &lt;&lt; "Error opening \"backgroundmusic.wav\"" &lt;&lt; std::endl;
      if (!sb_eating.loadFromFile("eatingsfx.wav"))
          if(DEBUG)
              std::cerr &lt;&lt; "Error opening \"eatingsfx.wav\"" &lt;&lt; std::endl;
      if (!sb_moving.loadFromFile("movingsfx.wav"))
          if(DEBUG)
              std::cerr &lt;&lt; "Error opening \"movingsfx.wav\"" &lt;&lt; std::endl;
      if (!sb_losing.loadFromFile("losingsfx.wav"))
          if(DEBUG)
              std::cerr &lt;&lt; "Error opening \"losingsfx.wav\"" &lt;&lt; std::endl;
      if (!sb_begin.loadFromFile("beginsfx.wav"))
          if(DEBUG)
              std::cerr &lt;&lt; "Error opening \"beginsfx.wav\"" &lt;&lt; std::endl;
  
      //s_eating.setBuffer(sb_eating);
      //s_moving.setBuffer(sb_moving);
      //s_losing.setBuffer(sb_losing);
      //s_begin.setBuffer(sb_begin);
      addMusic(std::string("backgroundMusic"), std::move(backgroundMusic));
      addSound(s_eating, sb_eating, std::string("eating"));
      addSound(s_moving, sb_moving, std::string("moving"));
      addSound(s_losing, sb_losing, std::string("losing"));
      addSound(s_begin, sb_begin, std::string("begin"));
  }
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/30EgB.jpg" alt="enter image description here"></p>