SFML community forums

Help => Audio => Topic started by: IvanX507 on January 04, 2015, 12:27:13 am

Title: Failed to open sound file "music.ogg" (Error : flac decoder lost sync.)
Post by: IvanX507 on January 04, 2015, 12:27:13 am
Hello
I have a problem:
I starting to use SFML 2.1  and I made a simple code that show a sprite and the sprite moves. All ok
I decide to put a music to test and when i compile all ok.
when I run said this in the console:
Failed to open sound file "music.ogg" (Error : flac decoder lost sync.)
And don't play the music.
You can help me with this please?
Thanks :D

Software:
Qt Creator 3.0.1
SFML 2.1
Title: Re: Failed to open sound file "music.ogg" (Error : flac decoder lost sync.)
Post by: Ixrec on January 04, 2015, 12:41:05 am
This could be as simple as a corrupt music file. Could you upload your music.ogg?
Title: Re: Failed to open sound file "music.ogg" (Error : flac decoder lost sync.)
Post by: IvanX507 on January 04, 2015, 02:58:08 am
This is the song:
https://cloud.openmailbox.org/public.php?service=files&t=db2cc8a346d0a80778087b55926d87db
Title: Re: Failed to open sound file "music.ogg" (Error : flac decoder lost sync.)
Post by: G. on January 04, 2015, 03:04:29 am
I replaced one of my music in one of my game by your music, and it doesn't work but I had a different error message:
Failed to open sound file "music.ogg" Supported file format but file is malformed.

It seems something is wrong with your file.
Title: Re: Failed to open sound file "music.ogg" (Error : flac decoder lost sync.)
Post by: IvanX507 on January 04, 2015, 03:18:34 am
Thanks :D
I will use other to test.
I really happy that is the file and not the code.
Title: Re: (SOLVED)Failed to open sound file "music.ogg" (Error : flac decoder lost sync.)
Post by: IvanX507 on January 04, 2015, 03:31:02 am
I tested other and now only not load the sound : /
Title: Re: Failed to open sound file "music.ogg" (Error : flac decoder lost sync.)
Post by: G. on January 04, 2015, 03:46:26 am
Maybe your code is wrong too. :p
Title: Re: Failed to open sound file "music.ogg" (Error : flac decoder lost sync.)
Post by: IvanX507 on January 04, 2015, 03:51:23 am


This is the Game.cpp
[spoiler]
#include <iostream>
#include "Game.h"
using namespace std;
using namespace sf;


zombie::zombie():ventana(VideoMode(800, 600),"Game") {

}

int zombie::inicia(){
    ventana.setFramerateLimit(60);
    ventana.setKeyRepeatEnabled(true);
    ventana.setVerticalSyncEnabled(true);

   if (!hero_texture.loadFromFile("hero.png")){
       return 1;
   }
    hero_texture.setSmooth(true);
    hero_texture.setRepeated(true);
    hero_sprite.setTexture(hero_texture);
    hero_sprite.setPosition(400, 400);

    if (!lalala.openFromFile("music.ogg")){
        cout << "error" <<endl;
        return -1;
    }
    lalala.setVolume(100);

}




void zombie::evento_i() {
        //Eventos de la ventana
    while(ventana.pollEvent(evento)){
        if (evento.type == Event::Closed){
           lel = false;
        }
    }
    //Eventos del heroe
    if(Keyboard::isKeyPressed(Keyboard::Up)){
        UP = true;
    }
    if(Keyboard::isKeyPressed(Keyboard::Down)){
        DOWN = true;
    }
    if(Keyboard::isKeyPressed(Keyboard::Left)){
        LEFT = true;
    }
    if(Keyboard::isKeyPressed(Keyboard::Right)){
        RIGHT = true;
    }
    if (Keyboard::isKeyPressed(Keyboard::S)){
        SOUND = true;
    }
}

void zombie::update() {
    Vector2f movimiento_heroe(0.f,0.f);
    float velocidad_heroe = 3.f;

    if (UP){
      movimiento_heroe.y-= 1.f * velocidad_heroe;
      UP = false;
    }

    if (DOWN){
      movimiento_heroe.y= 1.f * velocidad_heroe;
      DOWN = false;
    }

    if (LEFT){
      movimiento_heroe.x-= 1.f * velocidad_heroe;
      LEFT = false;
    }

    if (RIGHT){
      movimiento_heroe.x= 1.f * velocidad_heroe;
      RIGHT = false;
    }
    hero_sprite.move(movimiento_heroe);
    if(SOUND){
        music.play();
    }
}


void zombie::render() {
    lalala.play();
    ventana.clear(Color::Blue);
    ventana.draw(hero_sprite);
    ventana.display();

}

void zombie::clear(){
    ventana.close();
}

void zombie::corre(){
    inicia();
    while(lel){
        evento_i();
        update();
        render();
    }
    clear();
}
[/spoiler]

(click to show/hide)

I'm using the tutorials of the SFML 2.1 page
I'm doing bad? xD
Title: Re: Failed to open sound file "music.ogg" (Error : flac decoder lost sync.)
Post by: Ixrec on January 04, 2015, 03:59:05 am
The sf::Music object called "music" never has loadFromFile called on it, so I wouldn't be surprised if you aren't hearing that one.

The one called "lalala" has play() called on it in the render() method every frame, which is very strange and definitely unnecessary, though it doesn't seem like that should cause any problems.

Also, it has been waaaaay too long since I studied Spanish.  Seeing "ventana" refer to a GUI window instead of a physical window on the side of a house just looks weird to me.
Title: Re: Failed to open sound file "music.ogg" (Error : flac decoder lost sync.)
Post by: IvanX507 on January 04, 2015, 04:07:05 am
Well yes :
ventana = window
lalala = I had trying to make work the music and i changed the variable with a random name :P
zombie = principal class
evento = event :v
the others are for movement,speed,etc.
Title: Re: Failed to open sound file "music.ogg" (Error : flac decoder lost sync.)
Post by: G. on January 04, 2015, 06:34:26 am
Quote from: http://www.sfml-dev.org/documentation/2.1/classsf_1_1SoundStream.php#afdc08b69cab5f243d9324940a85a1144
This function starts the stream if it was stopped, resumes it if it was paused, and restarts it from the beginning if it was already playing.
You call play() every frame, so lalala restarts every frame and you can't hear it. ;)
Call play() only once, when you want the music to start playing.

Why don't you use SFML 2.2 by the way?
Title: Re: Failed to open sound file "music.ogg" (Error : flac decoder lost sync.)
Post by: IvanX507 on January 04, 2015, 07:02:24 pm
Thank Thanks Thanks :D
for all the help

but I don't use the sfml 2.2 because I have some compatibilities problems xP
Title: Re: Failed to open sound file "music.ogg" (Error : flac decoder lost sync.)
Post by: Ixrec on January 04, 2015, 07:11:53 pm
I have some compatibilities problems xP

Could you elaborate? The minor versions of SFML definitely aren't ABI compatible, but that shouldn't affect anyone developing new code.
Title: Re: Failed to open sound file "music.ogg" (Error : flac decoder lost sync.)
Post by: NicolaStuka on January 18, 2016, 09:38:55 pm
I had the same problem, the libsnd file is incorrect .

Late but safe jeeejej