Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Desktop] Music getPosition() not accurate on desktop for MP3s #5692

Closed
thebnich opened this issue Jun 29, 2019 · 5 comments
Closed

[Desktop] Music getPosition() not accurate on desktop for MP3s #5692

thebnich opened this issue Jun 29, 2019 · 5 comments

Comments

@thebnich
Copy link

Music.getPosition() lags behind the actual sound position on desktop. Using the code below, the sound is noticeably out of sync after just a few seconds. Everything works as expected on Android and iOS.

Using the latest GDX release (1.9.9).

package com.bnich.soundtest;

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.graphics.GL20;

public class Game extends ApplicationAdapter {
    Music music;

    @Override
    public void create() {
        // https://www.dropbox.com/s/foyn8lps7rihwkw/60bpm.mp3?dl=0
        music = Gdx.audio.newMusic(Gdx.files.internal("60bpm.mp3"));
        music.play();
    }

    @Override
    public void render() {
        float beat = music.getPosition() % 1;
        if (beat < 0.05f)
            Gdx.gl.glClearColor(1, 1, 1, 1);
        else
            Gdx.gl.glClearColor(0, 0, 0, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    }
}

@thebnich
Copy link
Author

After looking into solutions for the similar issue #5693, I was inspired to try a different audio format. As with #5693, using WAV/OGG does, in fact, fix the issue. Unlike #5693, however, this issue isn't triggered by doing a seek first; the music position loses accuracy simply while playing the MP3, which still seems like a bug. Updating title accordingly.

@thebnich thebnich changed the title Music getPosition() not accurate on desktop Music getPosition() not accurate on desktop for MP3s Jun 29, 2019
@MrStahlfelge
Copy link
Member

Can you prefix the title with [Desktop]? Thanks

@thebnich thebnich changed the title Music getPosition() not accurate on desktop for MP3s [Desktop] Music getPosition() not accurate on desktop for MP3s Jul 1, 2019
mgsx-dev added a commit to mgsx-dev/libgdx that referenced this issue Sep 14, 2019
@mgsx-dev
Copy link
Contributor

@thebnich i included your MP3 file in libgdx tests within my PR #5793. Please tell me if it's OK for you.

@thebnich
Copy link
Author

Nice PR!

I don't own the license to the MP3 originally linked to above, so I just replaced it with a new one generated with Audacity (link). Feel free to include this in the tests.

@mgsx-dev
Copy link
Contributor

@thebnich thank you, i replaced it. It's even better, it has different sounds on note / quarter note :-)

Tom-Ski added a commit that referenced this issue Sep 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants