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

Author Topic: [CLOSED] Can't resume music after pause  (Read 4388 times)

0 Members and 1 Guest are viewing this topic.

DragonRock

  • Newbie
  • *
  • Posts: 14
    • View Profile
[CLOSED] Can't resume music after pause
« on: June 28, 2017, 04:07:00 pm »
Hi,

first of all, thanks for SFML, which is the best multimedia library for C++ to me.

Recently, I've been trying to make a small music player in Rust. For this, I use Rust-SFML which is based on CSFML itself based on SFML. To solve some trouble, I came back to C++, and I have the following problem : once I pause a music, there's no way to resume the playing. getStatus gives me sf::Sound::Platying, but there's no sound in my earplugs.

I think it might be something stupid, but I can't see what.

#include <iostream>
#include <chrono>
#include <thread>
#include <cassert>
#include <SFML/Audio/Music.hpp>
#include <SFML/Audio/Sound.hpp>

int main(int argc, char *argv[])
{
    sf::Music music;
    if (!music.openFromFile("resources/orchestral.ogg")) {
        return 1;
    }

    music.play();
    assert(music.getStatus() == sf::Sound::Playing);

    std::this_thread::sleep_for(std::chrono::seconds(5));

    music.pause();
    assert(music.getStatus() == sf::Sound::Paused);

    music.play();
    assert(music.getStatus() == sf::Sound::Playing);

    std::this_thread::sleep_for(std::chrono::seconds(10));

    return 0;
}

that I compile with

g++ -g -std=c++14 main.cpp -o main -lsfml-audio

I run on ArchLinux, I tried this with gcc 7.1.1 and clang 4.0.1, and I'm using SFML 2.4.2.

Do you have any hints ?

Thanks in advance !

EDIT : Added the -g flag in the compilation command line for the assert to be taken into account.
« Last Edit: July 03, 2017, 11:22:00 am by DragonRock »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Can't resume music after pause
« Reply #1 on: June 28, 2017, 04:32:50 pm »
assert gets completely removed (no op) when not compiled in debug mode (-g flag).
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

DragonRock

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Can't resume music after pause
« Reply #2 on: June 28, 2017, 04:39:54 pm »
Well spotted, I tried with the -g flag. I had the same results though (initially, I had std::cout << .. but I replaced it with asserts because I thought it would be more clear).
« Last Edit: June 28, 2017, 04:43:23 pm by DragonRock »

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Can't resume music after pause
« Reply #3 on: July 01, 2017, 03:26:03 pm »
Tested this (on Windows).
Works fine  :-\

Does the sound stop when you pause it and then become silent when you resume it?
Have you tried querying the current play position?
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

DragonRock

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Can't resume music after pause
« Reply #4 on: July 03, 2017, 09:35:25 am »
I added a
std::cout << music.getPlayingOffset().asMilliseconds() << std::endl;
before and after the last sleep, and I get this on the terminal
4969
4969

It's kind of weird, I asked a friend to try this on ubuntu to see if he has the same problem, and it seems to work correctly on ubuntu, he gets this
4966
14991

It might be a problem with my alsa or something...

EDIT: I think the problem is not with sfml, but most likely with my sound configuration. Anyway, to solve this problem, I basically re-coded the pause function, instead of pausing, I store the playing offset, and I stop the sound. When play is triggered, if it was paused, I play the sound from start and instantly change the playing offset to what is was before. It's quite uggly, but it works.

Thank you !
« Last Edit: July 03, 2017, 11:21:51 am by DragonRock »