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

SoundChannel#position reports seconds instead of milliseconds #1290

Closed
Gama11 opened this issue Sep 29, 2016 · 1 comment
Closed

SoundChannel#position reports seconds instead of milliseconds #1290

Gama11 opened this issue Sep 29, 2016 · 1 comment

Comments

@Gama11
Copy link
Member

Gama11 commented Sep 29, 2016

import openfl.events.Event;
import openfl.display.Sprite;

class Main extends Sprite  {
    public function new() {
        super();
        var sound = openfl.Assets.getMusic("assets/mode.ogg");
        trace(sound.length);
        var channel = sound.play();

        addEventListener(Event.ENTER_FRAME, function(_) trace(channel.position));
    }
}

Sound used for testing: mode.ogg
OpenFL 4.2.0, Lime 3.2.1

On Neko, sound.length traces 8698 like expected. However, the sound position is in seconds instead of milliseconds:

Main.hx:11: 0
Main.hx:11: 0.02
Main.hx:11: 0.02
Main.hx:11: 0.02
Main.hx:11: 0.04
Main.hx:11: 0.06
Main.hx:11: 0.081
Main.hx:11: 0.101
Main.hx:11: 0.121
Main.hx:11: 0.121
[...]

The correct unit (ms) is reported on Flash, HTML5 and OpenFL legacy.


Now, this would be easy to work around in Flixel (just multiply by 1000 if !openfl_legacy) if it wasn't for the following issue:

If you set a startTime in sound.play() (for instance sound.play(500);), channel.position gets stuck at that:

Main.hx:11: 500
Main.hx:11: 500
Main.hx:11: 500
Main.hx:11: 500
Main.hx:11: 500
Main.hx:11: 500
Main.hx:11: 500
Main.hx:11: 500
Main.hx:11: 500
Main.hx:11: 500
Main.hx:11: 500
Main.hx:11: 500
Main.hx:11: 500
Main.hx:11: 500

So it sometimes reports seconds, sometimes milliseconds.

@Gama11
Copy link
Member Author

Gama11 commented Sep 30, 2016

Thanks for the quick fix, appears to work as expected now! :)

@jgranick jgranick modified the milestone: Sound API Sep 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants