fredsa / playn

Cross platform game library for N≥4 platforms
0 stars 1 forks source link

Problem with sound callbacks (introduced with issue #130) #143

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
There is a problem when loading twice the same sound on HTML/Android platforms 
(seems OK on Java platform) : the first time the sound is loaded, everything is 
already, the callback is correctly called, but the second time the sound is 
loaded, the callback is never raised again...

What steps will reproduce the problem?
1. Simply load a sound a first time in the game logic, using a callback.

2. A few second later, try to load the same sound again, with a new callback : 
neither the callback error nor done methods are called and thus block the game 
logic...

// Try to load a sound, with a callback.
final String path = "sounds/death";
final Sound sound1 = PlayN.assets().getSound(path);
sound1.addCallback(new ResourceCallback<Sound>() {
    @Override
    public void error(final Throwable err) {
        PlayN.log().error("not loaded", err);
    }
    @Override
    public void done(final Sound resource) {
        PlayN.log().debug("loaded");

        //  .... wait a bit ....

        // Try to load again the same sound, with a callback
        // but the callback is never called.......
        final Sound sound2 = PlayN.assets().getSound(path);
        sound2.addCallback(new ResourceCallback<Sound>() {
            @Override
            public void error(final Throwable err) {
                PlayN.log().error("not loaded", err);
            }
            @Override
            public void done(final Sound resource) {
                PlayN.log().debug("loaded");
            }
        });
    }
});

What is the expected output? What do you see instead?

Expected output is that the callback should be called even if the same sound is 
loaded twice or more times.

What version of the product are you using? On what operating system?

PlayN 1.2-SNAPSHOT, Windows 7
Issue seems to only happen on HTML and Android platforms. Java works correctly.

Please provide any additional information below.

It noticed a problem : inside the AbstractSound class (from which AndroidSound 
and HtmlSound classes inherits from), the member "soundLoaded" is never set. 
Maybe it's the reason of this problem :)

Original issue reported on code.google.com by mbarbe...@gmail.com on 27 Feb 2012 at 8:20

GoogleCodeExporter commented 9 years ago
Additionnal problem with the same code running under Mozilla Firefox 10 :

- Even the first time I try to load a sound, the callback isn't called (neither 
the error nor done methods are called)

- Strange behaviour, when the first sound has finished to load, it is played 
automatically...

Original comment by mbarbe...@gmail.com on 6 Mar 2012 at 8:07

GoogleCodeExporter commented 9 years ago
I had the same issues, so I manually changed this in my clone of playn, can 
like original poster says, be fixed by adding soundLoaded = true; to the 
onLoadComplete callback. I attached a patch for it, not that it's needed.

Original comment by simen...@gmail.com on 22 May 2012 at 1:25

Attachments:

GoogleCodeExporter commented 9 years ago
Fixed.

Original comment by m...@samskivert.com on 22 May 2012 at 6:13