fredsa / playn

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

Sound fails to load after the first on Linux Java; works fine in HTML mode #169

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a project from the 1.2 archetype.

2. Put six short mp3 files (sound effects) into your resources folder. Let's 
call them 0.mp3, 1.mp3, ..., 5.mp3.

3. Make your game use this implementation. It's going to load the five files.

    private List<Sound> sounds = new ArrayList<Sound>();

    @Override
    public void init() {
        // create and add background image layer
        Image bgImage = assets().getImage("images/bg.png");
        ImageLayer bgLayer = graphics().createImageLayer(bgImage);
        graphics().rootLayer().add(bgLayer);

        for (int i=0; i<6; i++) {
            Sound sound = assets().getSound(i + "");
            sounds.add(sound);
        }

        keyboard().setListener(new Keyboard.Adapter() {
            int i;
            @Override
            public void onKeyDown(Event event) {
                sounds.get(i).play();
                i = (i+1) % 6;
            }
        });
    }

(update and paint don't matter)

4. Run it in Java mode on Linux (64-bit, Ubuntu 12.04, Java 1.6 or 1.7 latest) 
and also run in HTML mode.

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

In Java mode, after the first file loads, the rest throw exceptions and produce 
stack traces. These don't stop the game. The trace looks like this:

Failed to open sound 1.mp3
javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 
11025.0 Hz, 16 bit, mono, 2 bytes/frame, little-endian not supported.
    at com.sun.media.sound.DirectAudioDevice$DirectDL.implOpen(DirectAudioDevice.java:494)
    at com.sun.media.sound.DirectAudioDevice$DirectClip.implOpen(DirectAudioDevice.java:1280)
    at com.sun.media.sound.AbstractDataLine.open(AbstractDataLine.java:107)
    at com.sun.media.sound.DirectAudioDevice$DirectClip.open(DirectAudioDevice.java:1061)
    at com.sun.media.sound.DirectAudioDevice$DirectClip.open(DirectAudioDevice.java:1151)
    at playn.java.JavaSound.init(JavaSound.java:94)
    at playn.java.JavaSound.access$000(JavaSound.java:34)
    at playn.java.JavaSound$1.run(JavaSound.java:47)
    at playn.java.JavaAssets.doResourceAction(JavaAssets.java:48)
    at playn.java.JavaSound.<init>(JavaSound.java:45)
    at playn.java.JavaAudio.createSound(JavaAudio.java:28)
    at playn.java.JavaAssets.doGetSound(JavaAssets.java:101)
    at playn.core.AbstractAssets.getSound(AbstractAssets.java:49)
    [and then the init method from the sample code]

Note that it doesn't matter what the sample rate, stereo/mono, etc of the mp3 
file is; this happens on every mp3 I've tried.

If you run the same code in HTML mode, it runs happily.

What version of the product are you using? On what operating system?
PlayN 1.2. As mentioned above, 64-bit Linux Ubuntu 12.04 with Java 6, and tried 
it on 7 with the same results.

Please provide any additional information below.

I tried the same code on Windows 7 64-bit (dual boot, same hardware), and it 
worked fine in both Java and HTML mode.

I have attached the sample mp3 file (0.mp3) that I've happened to use in my 
test case. It's a simple explosion sound effect.

Original issue reported on code.google.com by Paul.Ges...@gmail.com on 12 May 2012 at 2:31

Attachments:

GoogleCodeExporter commented 9 years ago
You'll probably using OpenJDK on Linux, which needs some help in the sound 
department. Can you try a JDK from 
http://www.oracle.com/technetwork/java/javase/downloads/index.html ?

Original comment by fredsa@google.com on 12 May 2012 at 2:57

GoogleCodeExporter commented 9 years ago
If anyone has good instructions on getting mp3 files to playback on Linux / 
OpenJDK, let me know, and I'll add the instructions to the getting started wiki 
:)

Original comment by fredsa@google.com on 12 May 2012 at 2:58

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
This is on Oracle's VMs. Specifically, 1.6.0_26-b03 and 1.7.0_04-b20.

(Deleted original comment and re-added due to a typo.)

Original comment by Paul.Ges...@gmail.com on 12 May 2012 at 10:47

GoogleCodeExporter commented 9 years ago
Upon further investigation, I have discovered that the problem only occurs with 
the Java 6 JRE. When I run the project with the Java 7 JRE, it loads the sounds 
and plays them back as expected.

(For the curious, I had changed my Eclipse project settings to use the 1.7 JDK, 
but the Debug execution of the Java application was still set to use 1.6 
[project default] instead of the workspace default.)

Original comment by Paul.Ges...@gmail.com on 12 May 2012 at 7:19