Java application shows and error when trying to play sound

Hi,
I have built successfully snap for Java application but at runtime when I try to test notification sound I’m getting an error. I’m not quite sure what’s wrong from the stack trace. Do I missing some plugs or this is access permission related?

Here bellow is relevant snaps parts or at github.

Launcher script:

#!/bin/sh

JAVA_BIN="$JAVA_HOME/bin/java"

export DESKTOP_SESSION=gnome
export XDG_SESSION_DESKTOP=gnome
export XDG_CURRENT_DESKTOP=GNOME

# Fix font / theme

export _JAVA_OPTIONS='-Dsun.java2d.xrender=true -Dprism.useFontConfig=false -Dawt.useSystemAAFontSettings=on -Dswing.aatext=true -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel -Dswing.crossplatformlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel'
export JAVA_FONTS=$SNAP/usr/share/fonts/truetype

exec $SNAP/bin/padsp $JAVA_BIN -verbose:jni -jar -Duser.home=$SNAP_USER_COMMON $SNAP/Chatty.jar "$@"

snapcraft.yaml:

name: chatty
version: "0.12"
summary: Twitch Chat Client
description: |
  Chatty is a Twitch Chat Client for Desktop featuring many Twitch specific features.
base: core18

grade: stable
confinement: strict

apps:
  chatty:
    extensions:
      - gnome-3-28
    command: desktop-launch $SNAP/bin/launcher
    environment:
      JAVA_HOME: $SNAP/usr/lib/jvm/java-11-openjdk-amd64
      PATH: $JAVA_HOME/jre/bin:$PATH
      LD_LIBRARY_PATH: "$SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/pulseaudio"
    plugs:
      - home
      - network
      - opengl
      - pulseaudio
      - alsa

parts:
  chatty:
    plugin: nil
    override-build: |
      wget -O $SNAPCRAFT_PART_INSTALL/Chatty.v$SNAPCRAFT_PROJECT_VERSION.zip https://github.com/chatty/chatty/releases/download/v$SNAPCRAFT_PROJECT_VERSION/Chatty_$SNAPCRAFT_PROJECT_VERSION.zip
      unzip -o $SNAPCRAFT_PART_INSTALL/Chatty.v$SNAPCRAFT_PROJECT_VERSION.zip -d $SNAPCRAFT_PART_INSTALL/
      rm $SNAPCRAFT_PART_INSTALL/Chatty.v$SNAPCRAFT_PROJECT_VERSION.zip
    build-packages:
      - wget
      - unzip
      - openjdk-11-jre
      - ca-certificates
      - ca-certificates-java
    stage-packages:
      - openjdk-11-jre
      - libpulse0
      - libpulsedsp
      - libxxf86vm1
      - libgl1-mesa-dri
      - libglu1-mesa
      - libgl1-mesa-glx
      - libgles2-mesa
      - x11-xserver-utils
  launcher:
    plugin: dump
    source: snap/local
    organize:
      'launcher': 'bin/'
      'padsp': 'bin/'
      'sensible-browser': 'bin/'
      'usr/lib/*/gvfs/*.so': 'usr/lib'
      'usr/bin/xprop': 'usr/bin/xprop.disabled'

Error stack trace:

[2020-07-22 20:29:21/143 WARNING] Couldn't play sound (test//home/arturas/snap/chatty/common/sounds/ding.wav): java.lang.IllegalArgumentException: No line matching interface Clip supporting format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian is supported. [chatty.util.Sound/play]
java.lang.IllegalArgumentException: No line matching interface Clip supporting format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian is supported.
	at java.desktop/javax.sound.sampled.AudioSystem.getLine(AudioSystem.java:425)
	at chatty.util.Sound.play(Sound.java:56)
	at chatty.gui.components.settings.NotificationEditor$MyItemEditor$3.actionPerformed(NotificationEditor.java:442)
	at java.desktop/javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1967)
	at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2308)
	at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:405)
	at java.desktop/javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:262)
	at java.desktop/javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:279)
	at java.desktop/java.awt.Component.processMouseEvent(Component.java:6631)
	at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3342)
	at java.desktop/java.awt.Component.processEvent(Component.java:6396)
	at java.desktop/java.awt.Container.processEvent(Container.java:2263)
	at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5007)
	at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2321)
	at java.desktop/java.awt.Component.dispatchEvent(Component.java:4839)
	at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4918)
	at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4547)
	at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4488)
	at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2307)
	at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2772)
	at java.desktop/java.awt.Component.dispatchEvent(Component.java:4839)
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:772)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:95)
	at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:745)
	at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:743)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
	at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:742)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:117)
	at java.desktop/java.awt.WaitDispatchSupport$2.run(WaitDispatchSupport.java:190)
	at java.desktop/java.awt.WaitDispatchSupport$4.run(WaitDispatchSupport.java:235)
	at java.desktop/java.awt.WaitDispatchSupport$4.run(WaitDispatchSupport.java:233)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.desktop/java.awt.WaitDispatchSupport.enter(WaitDispatchSupport.java:233)
	at java.desktop/java.awt.Dialog.show(Dialog.java:1070)
	at java.desktop/java.awt.Component.show(Component.java:1716)
	at java.desktop/java.awt.Component.setVisible(Component.java:1663)
	at java.desktop/java.awt.Window.setVisible(Window.java:1031)
	at java.desktop/java.awt.Dialog.setVisible(Dialog.java:1005)
	at chatty.gui.components.settings.NotificationEditor$MyItemEditor.showEditor(NotificationEditor.java:627)
	at chatty.gui.components.settings.NotificationEditor$MyItemEditor.showEditor(NotificationEditor.java:205)
	at chatty.gui.components.settings.TableEditor.editItem(TableEditor.java:563)
	at chatty.gui.components.settings.TableEditor.editSelectedItem(TableEditor.java:531)
	at chatty.gui.components.settings.TableEditor.access$200(TableEditor.java:48)
	at chatty.gui.components.settings.TableEditor$ButtonAction.actionPerformed(TableEditor.java:716)
	at java.desktop/javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1967)
	at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2308)
	at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:405)
	at java.desktop/javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:262)
	at java.desktop/javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:279)
	at java.desktop/java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:297)
	at java.desktop/java.awt.Component.processMouseEvent(Component.java:6631)
	at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3342)
	at java.desktop/java.awt.Component.processEvent(Component.java:6396)
	at java.desktop/java.awt.Container.processEvent(Container.java:2263)
	at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5007)
	at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2321)
	at java.desktop/java.awt.Component.dispatchEvent(Component.java:4839)
	at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4918)
	at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4547)
	at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4488)
	at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2307)
	at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2772)
	at java.desktop/java.awt.Component.dispatchEvent(Component.java:4839)
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:772)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:95)
	at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:745)
	at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:743)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
	at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:742)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:117)
	at java.desktop/java.awt.WaitDispatchSupport$2.run(WaitDispatchSupport.java:190)
	at java.desktop/java.awt.WaitDispatchSupport$4.run(WaitDispatchSupport.java:235)
	at java.desktop/java.awt.WaitDispatchSupport$4.run(WaitDispatchSupport.java:233)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.desktop/java.awt.WaitDispatchSupport.enter(WaitDispatchSupport.java:233)
	at java.desktop/java.awt.Dialog.show(Dialog.java:1070)
	at java.desktop/java.awt.Component.show(Component.java:1716)
	at java.desktop/java.awt.Component.setVisible(Component.java:1663)
	at java.desktop/java.awt.Window.setVisible(Window.java:1031)
	at java.desktop/java.awt.Dialog.setVisible(Dialog.java:1005)
	at chatty.gui.components.settings.SettingsDialog.showSettings(SettingsDialog.java:376)
	at chatty.gui.components.settings.SettingsDialog.showSettings(SettingsDialog.java:337)
	at chatty.gui.MainGui$MainMenuListener.actionPerformed(MainGui.java:1512)
	at java.desktop/javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1967)
	at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2308)
	at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:405)
	at java.desktop/javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:262)
	at java.desktop/javax.swing.AbstractButton.doClick(AbstractButton.java:369)
	at java.desktop/javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1020)
	at java.desktop/javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:1064)
	at java.desktop/java.awt.Component.processMouseEvent(Component.java:6631)
	at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3342)
	at java.desktop/java.awt.Component.processEvent(Component.java:6396)
	at java.desktop/java.awt.Container.processEvent(Container.java:2263)
	at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5007)
	at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2321)
	at java.desktop/java.awt.Component.dispatchEvent(Component.java:4839)
	at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4918)
	at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4547)
	at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4488)
	at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2307)
	at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2772)
	at java.desktop/java.awt.Component.dispatchEvent(Component.java:4839)
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:772)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:95)
	at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:745)
	at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:743)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
	at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:742)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
1 Like

You probably want to replace pulseaudio with audio-playback in your plugs section.

am having the same problem:
Exception in thread “Thread-6” java.lang.IllegalArgumentException: No line matching interface SourceDataLine supporting format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian is supported.

my snapcraft.yaml file:

name: snake-on-the-chase # you probably want to 'snapcraft register <name>'
base: core18 # the base snap is the execution environment for this snap, with core18 Java Sound didn't work, so used core instead!!
version: '3.0' # just for humans, typically '1.2+git' or '1.3.2'
summary: Snake on the chase is a classic snake game with added flavours # 79 char long summary
description: |
  A Game with simple goal: Guide snake to the rats, feeding on them give you points and increases stamina
  Stamina of snake decreases gradually, so keep eating rats to recover
  Touching or passing throuh cactuses drains stamina drastically, avoid them
  Once all rats are eaten, you move to next level
  Game is Over if you drain all stamina 

icon: share/doc/SnakeOnTheChase/logo.png
grade: stable # must be 'stable' to release into candidate/stable channels
confinement: strict # use 'strict' once you have the right plugs and slots

apps:
  snake-on-the-chase:
    command: bin/SnakeOnTheChase
    desktop: share/applications/SnakeOnTheChase.desktop    
    plugs: [unity7, network, home, pulseaudio, alsa, x11]
    environment:
      JAVA_HOME: $SNAP/usr/lib/jvm/java-11-openjdk-amd64 
      CLASSPATH: $SNAP/SnakeOnTheChase.jar
      PATH: $SNAP/usr/lib/jvm/java-11-openjdk-amd64/bin:$PATH
      # pulseaudio
      LD_LIBRARY_PATH: ${SNAP}/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/pulseaudio

parts:
  snake-on-the-chase:
    source: .
    plugin: dump
    organize:
      SnakeOnTheChase: bin/SnakeOnTheChase      
 

    stage-packages: [openjdk-11-jre, libpulse0, x11-utils]
    build-packages:
      - ca-certificates
      - ca-certificates-java
      - openjdk-11-jre

did you find the solution??

Hi @popey

I tried your solution (pulseaudio -> audio-playback) but now I get errors about xprop, which is weird since I have x11-utils as a stage package:

$ snap run jgalaxian
openjdk version "1.8.0_265"
OpenJDK Runtime Environment (build 1.8.0_265-8u265-b01-0ubuntu2~18.04-b01)
OpenJDK 64-Bit Server VM (build 25.265-b01, mixed mode)
java.io.IOException: Cannot run program "/usr/bin/xprop": error=2, No such file or directory

The only change I made was to change pulseaudio to audio-playback, so that seems fishy to me. xprop is in fact present in the snap:

 ls -l /snap/jgalaxian/current/usr/bin/xprop
 -rwxr-xr-x 1 root root 41256 Apr 21  2017 /snap/jgalaxian/current/usr/bin/xprop*

This tells me that something in the stack trace is calling this as a hard-coded path and not with ${SNAP}/usr/bin/xprop, right?. But this is a diversion because . . .

I switched to use openjdk-11 instead, which solved the xprop issue, which is good news. But there is still no sound using the audio-playback plug with the same error others have found:

Unable to start audio mixer. java.lang.IllegalArgumentException: No line matching interface SourceDataLine supporting format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian is supported.

Could this be simply a bug in snap/snapcraft?

I’ve made a response in No sound in java snap I think you’d appreciate. Particularly with your examples above, I’d remove the padsp wrapper since it should be unnecessary when setup like the link, and also the desktop-launch wrapper, since the gnome extension effectively does that itself and doubling up would just introduce delay launching the snap for no benefit.

Good stuff. I will experiment with all that. Thanks for the great post!

Thank you, @James-Carroll! After some experimentation I was able to get sound working with OpenJDK 11 again.

The only thing that tripped me up at the end was that adding the gnome-3-28 extension caused problems with Java fonts that prevented it from running. Once I removed the extension, it worked. I don’t need it in any case. When it was present, I got Null Pointer errors having to do with the java fonts.

To summarize my changes for anyone who stumbles across this:

My issue: Sound in my java game no longer worked with newer versions of snapd in Java 8. When I built a new snap in Java 8 the sound no longer worked.

Following the link from @James-Carroll in his comment above, I did this:

Updated openjdk-8-jdk to openjdk-11-jdk.

Added this to my app environment:

ALSA_CONFIG_PATH: ${SNAP}/etc/asound.conf

Added audio-playback to my plugs.

Added a layout to normalize where alsa lib is expected to be:

layout:
  /usr/lib/$SNAPCRAFT_ARCH_TRIPLET/alsa-lib:
    bind: $SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/alsa-lib

Added a new package to the runtime environment:

- libsound2-plugins

The commit is here, which might make seeing what needed doing easier:

And here is the snapcraft.yaml:

https://raw.githubusercontent.com/jsseidel/jgalaxian/master/snap/snapcraft.yaml

1 Like