Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Sound who doens't play.  (Read 2327 times)

0 Members and 1 Guest are viewing this topic.

Lolilolight

  • Hero Member
  • *****
  • Posts: 1232
    • View Profile
Sound who doens't play.
« on: April 02, 2015, 07:46:49 pm »
Hi!

I'm trying to play a sound but it doesn't play :

int main() {
    sf::SoundBuffer buffer;
    buffer.loadFromFile ("sounds/ballhurtbar.wav");
    sf::Sound sound;
    sound.setBuffer(buffer);
    sound.play();
    return 0;
}
 

OS : ubuntu LTS 64 bits.
SFML version : 2.2.

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Sound who doens't play.
« Reply #1 on: April 02, 2015, 07:56:24 pm »
Lolilolight you make me sick, you have been around how long now? 5+ years and you have 1.2k+ posts to your name. And you really can't even find such a simple mistake in your code? Or even try the examples from the tutorials? Or for that matter just look around the forums a little bit...

http://en.sfml-dev.org/forums/index.php?topic=17286.0

http://www.sfml-dev.org/tutorials/2.2/audio-sounds.php

The most common mistake is to let a sound buffer go out of scope (and therefore be destroyed) while a sound still uses it.

The same applies to sounds in general and not just buffers.

(BTW, thank you for at least not posting a wall of code)

And just for the record...
(click to show/hide)
« Last Edit: April 02, 2015, 08:01:01 pm by zsbzsb »
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Sound who doens't play.
« Reply #2 on: April 02, 2015, 08:42:56 pm »
And just to make sure that this thread does not end up going on forever, here's another spoiler with a complete working example (including build instructions).
Now there should be no reason at all to continue this thread.
(click to show/hide)
« Last Edit: April 02, 2015, 08:50:44 pm by Jesper Juhl »

Lolilolight

  • Hero Member
  • *****
  • Posts: 1232
    • View Profile
Re: Sound who doens't play.
« Reply #3 on: April 02, 2015, 09:40:50 pm »
Arg right this is non blocking, sorry sorry.