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

Author Topic: Failed to open sound file "music.ogg" (Error : flac decoder lost sync.)  (Read 8949 times)

0 Members and 1 Guest are viewing this topic.

IvanX507

  • Newbie
  • *
  • Posts: 7
    • View Profile
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
« Last Edit: January 04, 2015, 03:31:16 am by IvanX507 »

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Failed to open sound file "music.ogg" (Error : flac decoder lost sync.)
« Reply #1 on: January 04, 2015, 12:41:05 am »
This could be as simple as a corrupt music file. Could you upload your music.ogg?


G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: Failed to open sound file "music.ogg" (Error : flac decoder lost sync.)
« Reply #3 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.

IvanX507

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Failed to open sound file "music.ogg" (Error : flac decoder lost sync.)
« Reply #4 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.

IvanX507

  • Newbie
  • *
  • Posts: 7
    • View Profile
I tested other and now only not load the sound : /

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: Failed to open sound file "music.ogg" (Error : flac decoder lost sync.)
« Reply #6 on: January 04, 2015, 03:46:26 am »
Maybe your code is wrong too. :p

IvanX507

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Failed to open sound file "music.ogg" (Error : flac decoder lost sync.)
« Reply #7 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

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Failed to open sound file "music.ogg" (Error : flac decoder lost sync.)
« Reply #8 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.
« Last Edit: January 04, 2015, 04:01:01 am by Ixrec »

IvanX507

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Failed to open sound file "music.ogg" (Error : flac decoder lost sync.)
« Reply #9 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.

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: Failed to open sound file "music.ogg" (Error : flac decoder lost sync.)
« Reply #10 on: January 04, 2015, 06:34:26 am »
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?
« Last Edit: January 04, 2015, 06:37:55 am by G. »

IvanX507

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Failed to open sound file "music.ogg" (Error : flac decoder lost sync.)
« Reply #11 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

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Failed to open sound file "music.ogg" (Error : flac decoder lost sync.)
« Reply #12 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.

NicolaStuka

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: Failed to open sound file "music.ogg" (Error : flac decoder lost sync.)
« Reply #13 on: January 18, 2016, 09:38:55 pm »
I had the same problem, the libsnd file is incorrect .

Late but safe jeeejej