question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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);
    }
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
MrStahlfelgecommented, Jul 1, 2019

Can you prefix the title with [Desktop]? Thanks

0reactions
mgsx-devcommented, Sep 14, 2019

@thebnich thank you, i replaced it. It’s even better, it has different sounds on note / quarter note 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

MP3: a way to get position in milliseconds for any given byte ...
I know the total length of the stream in bytes and seconds, and then just "convert" the byteposition to the timescale. It might...
Read more >
Problems playing wav's and mp3's on my windows 10 pc
Hi, if you use windows media player it can be a codec issue. I would try to use another media player for testing....
Read more >
com.badlogic.gdx.audio.Music.play java code examples
How to use. play. method. in. com.badlogic.gdx.audio.Music ... @Override public void create () { // copy an internal mp3 to the external storage...
Read more >
mp3 music player application development using android
The project could not be going smoothly without the help of these people. First of all, I would like to express my appreciation...
Read more >
How can I play an MP3 from my desktop w/o opening an app?
Previously, in icon view, I was able to play audio MP3 files directly from the desktop - without them opening iTunes or QuickTime....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found