B4J Question WSL2 under Windows 10 for developing Linux GUI B4J app: how ?

peacemaker

Expert
Licensed User
Longtime User
Hi, All

Am i wrong thinking that GUI Linux apps can be used in Windows 10 WSL2 ?
I have installed Ubuntu in WSL.
How to setup\start it for GUI apps (and the main is for development in B4J) ?
 
Last edited:

peacemaker

Expert
Licensed User
Longtime User
Solved Found some way, but development result is ... buggy:

1) Setup WSL2 as described world widely.
2) Install some Linux version (i used Ubuntu)
2.1) Install graphic card drivers, for ex. helped me:
sudo add-apt-repository ppa:eek:ibaf/graphics-drivers
sudo apt update
sudo apt upgrade
1739702898899.png

3) Use under Windows the path to browse internal Linux home folder ("Ubuntu-24.04" - will be your installed distro name)
\\wsl.localhost\Ubuntu-24.04\home
4) Copy into your /home/user folder Linux Java JDK + JavaFX bundle (for ex. ~/dev/jdk11)
5) Copy b4j-bridge.jar
6) Give rights to all the files and folders in your home folder:
sudo chmod -R 777 /home/user
7) Start B4J-bridge with full path (!) to make sure that JavaFX modules are found:
~/dev/jdk11/bin/java -jar --module-path ~/dev/jdk11/javafx/lib --add-modules ALL-MODULE-PATH ~/dev/b4j-bridge.jar
2.jpg
8) Do not use in B4J (for development) settings like
#VirtualMachineArgs: -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -Dprism.maxvram=2G
9) Connect the bridge from B4J to the IP-address from B4J-bridge log output and ...
1.jpg
... and development of the GUI app is possible, but ...

... but secondly B4XPages next to B4XMainPage are not working well: visible, but non-moveable, views are not clickable :(
 
Last edited:
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
Other foundings in WSL2 under Win10:
1)
WARNING: package com.sun.glass.ui.win not in javafx.graphics
WARNING: package com.sun.prism.d3d not in javafx.graphics

2)
secondly B4XPages next to B4XMainPage are not working well: visible, but non-moveable, views are not clickable
... if they are "UTILITY" ! If they are "DECORATED" - they are OK !
B4XPages.GetNativeParent(Me).SetFormStyle("DECORATED")

But .AlwaysOnTop does not work:
B4XPages.GetNativeParent(Me).AlwaysOnTop = True

3) Bluetooth by jBluetooth v.1.01:
java.lang.UnsatisfiedLinkError: /tmp/bluecove_vlad_0/libbluecove_x64.so: libbluetooth.so: cannot open shared object file: No such file or directory
...
Native Library bluecove_x64 not available

4) Webcamera of Sarxos library:
(java:25191): Gdk-WARNING **: 15:53:01.646: XSetErrorHandler() called with a GDK error trap pushed. Don't do that.
Feb 16, 2025 3:53:07 PM com.github.sarxos.webcam.Webcam getDriver
INFO: WebcamDefaultDriver capture driver will be used
OpenJDK 64-Bit Server VM warning: You have loaded library /tmp/BridJExtractedLibraries11802898396338342551/libbridj.so which might have disabled stack guard. The VM will try to fix the stack guard now.
It's highly recommended that you fix the library with 'execstack -c <libfile>', or link it with '-z noexecstack'.
java.lang.RuntimeException: Library 'OpenIMAJGrabber' was not loaded successfully from file '/tmp/BridJExtractedLibraries11802898396338342551/OpenIMAJGrabber.so'
at org.bridj.BridJ.getNativeLibrary(BridJ.java:922)
at org.bridj.BridJ.getNativeLibrary(BridJ.java:901)
at org.bridj.BridJ.getNativeLibrary(BridJ.java:513)
at org.bridj.cpp.CPPRuntime.newCPPInstance(CPPRuntime.java:627)
at org.bridj.cpp.CPPRuntime$CPPTypeInfo.initialize(CPPRuntime.java:828)
at org.bridj.cpp.CPPRuntime$CPPTypeInfo.initialize(CPPRuntime.java:755)
at org.bridj.CRuntime$CTypeInfo.initialize(CRuntime.java:209)
at org.bridj.BridJ.initialize(BridJ.java:970)
at org.bridj.NativeObject.<init>(NativeObject.java:23)
at org.bridj.StructObject.<init>(StructObject.java:14)
at org.bridj.cpp.CPPObject.<init>(CPPObject.java:27)
at com.github.sarxos.webcam.ds.buildin.natives.OpenIMAJGrabber.<init>(OpenIMAJGrabber.java:64)
at com.github.sarxos.webcam.ds.buildin.WebcamDefaultDriver$WebcamNewGrabberTask.handle(WebcamDefaultDriver.java:55)
at com.github.sarxos.webcam.WebcamProcessor$AtomicProcessor.run(WebcamProcessor.java:81)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
at java.base/java.lang.Thread.run(Thread.java:832)
Error occurred on line: 51 (SarxosWebCam)
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:132)
at peacemaker.orionlab.sarxoswebcam._getwebcams(sarxoswebcam.java:269)
at peacemaker.orionlab.sarxoswebcam._webcam_names(sarxoswebcam.java:103)
at peacemaker.orionlab.b4xmainpage._lblcamera_mouseclicked(b4xmainpage.java:4061)
at peacemaker.orionlab.b4xmainpage._menu2_itemclicked(b4xmainpage.java:5590)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessor
Impl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:629)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:237)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at jdk.internal.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:111)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:100)
at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:513)
at anywheresoftware.b4a.keywords.Common.CallSubNew3(Common.java:476)
at peacemaker.orionlab.aspopupmenu._itemclicked(aspopupmenu.java:1011)
at peacemaker.orionlab.aspopupmenu._clickitem(aspopupmenu.java:940)
at peacemaker.orionlab.aspopupmenu._item_mouseclicked(aspopupmenu.java
:1924)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:629)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:237)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at jdk.internal.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:111)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:100)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:98)
at anywheresoftware.b4j.objects.NodeWrapper$1.h
andle(NodeWrapper.java:109)
at anywheresoftware.b4j.objects.NodeWrapper$1.handle(NodeWrapper.java:1)
at javafx.base/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:234)
at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at javafx.base/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatche
r.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at javafx.base/com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.base/javafx.event.Event.fireEvent(Event.java:198)
at javafx.graphics/javafx.scene.Scene$ClickGenerator.postProcess(Scene.java:3597)
at javafx.graphics/javafx.scene.Scene$MouseHandler.process(Scene.java:3899)
at javafx.graphics/javafx.scene.Scene.processMouseEvent(Scene.java:1885)
at javafx.graphics/javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2618)
at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:409)
~e:
at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:299)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(GlassViewEventHandler.java:447)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:412)
at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:446)
at javafx.graphics/com.sun.glass.ui.View.handleMouseEvent(View.java:556)
at javafx.graphics/com.sun.glass.ui.View.notifyMouse(View.java:942)
at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$11(GtkApplication.java:277)
at java.base/java.lang.Thread.run(Thread.java:832)
Caused by: com.github.sarxos.webcam.WebcamException: java.util.concurrent.ExecutionExce
ption: com.github.sarxos.webcam.WebcamException: Cannot execute task
at com.github.sarxos.webcam.WebcamDiscoveryService.getWebcams(WebcamDiscoveryService.java:124)
at com.github.sarxos.webcam.Webcam.getWebcams(Webcam.java:893)
at com.github.sarxos.webcam.Webcam.getWebcams(Webcam.java:866)
at com.github.sarxos.webcam.Webcam.getWebcams(Webcam.java:845)
... 71 more
Caused by: java.util.concurrent.ExecutionException: com.github.sarxos.webcam.WebcamException: Cannot execute task
at java.base/java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.base/java.util.concurrent.FutureTask.get(FutureTask.java:191)
at com.github.sarxos.webcam.WebcamDiscoveryService.getWebcams(WebcamDiscoveryService.java:116)
... 74 more
Caused by: com.github.sarxos.webcam.WebcamException: Cannot execute task
at com.github.sarxos.webcam.WebcamProcessor$AtomicProcessor.process(WebcamProcessor.java:72)
at com.github.sarxos.webcam.WebcamProcessor.process(WebcamProcessor.java:140)
at com.github.sarxos.webcam.WebcamTask.
process(WebcamTask.java:46)
at com.github.sarxos.webcam.ds.buildin.WebcamDefaultDriver$WebcamNewGrabberTask.newGrabber(WebcamDefaultDriver.java:45)
at com.github.sarxos.webcam.ds.buildin.WebcamDefaultDriver.getDevices(WebcamDefaultDriver.java:117)
at com.github.sarxos.webcam.WebcamDiscoveryService$WebcamsDiscovery.call(WebcamDiscoveryService.java:36)
at com.github.sarxos.webcam.WebcamDiscoveryService$WebcamsDiscovery.call(WebcamDiscoveryService.java:26)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
... 1 more
Caused by: java.lang.RuntimeException: Failed to allocate new instance of type class com.github.sarxos.webcam.ds.buildin.natives.OpenIMAJGrabber
at org.bridj.cpp.CPPRuntime.newCPPInstance(CPPRuntime.java:674)
at org.bridj.cpp.CPPRuntime$CPPTypeInfo.initialize(CPPRuntime.java:828)
at org.
bridj.cpp.CPPRuntime$CPPTypeInfo.initialize(CPPRuntime.java:755)
at org.bridj.CRuntime$CTypeInfo.initialize(CRuntime.java:209)
at org.bridj.BridJ.initialize(BridJ.java:970)
at org.bridj.NativeObject.<init>(NativeObject.java:23)
at org.bridj.StructObject.<init>(StructObject.java:14)
at org.bridj.cpp.CPPObject.<init>(CPPObject.java:27)
at com.github.sarxos.webcam.ds.buildin.natives.OpenIMAJGrabber.<init>(OpenIMAJGrabber.java:64)
at com.github.sarxos.webcam.ds.buildin.WebcamDefaultDriver$WebcamNewGrabberTask.handle(WebcamDefaultDriver.java:55)
at com.github.sarxos.webcam.WebcamProcessor$AtomicProcessor.run(WebcamProcessor.java:81)
... 3 more
Caused by: java.lang.RuntimeException: Library 'OpenIMAJGrabber' was not loaded successfully from file '/tmp/BridJExtractedLibraries11802898396338342551/OpenIMAJGrabber.so'
at org.bridj.BridJ.getNativeLibrary(BridJ.java:922)
at org.bridj.BridJ.getNativeLibrary(BridJ.java:901)
at org.bridj.BridJ.getNativeLibrary(BridJ.java:513)
at org.bridj.cpp.CPPRuntime.newCPPI
nstance(CPPRuntime.java:627)
... 13 more
# BridJ: dlopen error when loading /tmp/BridJExtractedLibraries11802898396338342551/OpenIMAJGrabber.so : libv4l2.so.0: cannot open shared object file: No such file or directory
# BridJ: dlopen error when loading /tmp/BridJExtractedLibraries11802898396338342551/OpenIMAJGrabber.so : libv4l2.so.0: cannot open shared object file: No such file or directory
# BridJ: dlopen error when loading /tmp/BridJExtractedLibraries11802898396338342551/OpenIMAJGrabber.so : libv4l2.so.0: cannot open shared object file: No such file or directory
# BridJ: dlopen error when loading /tmp/BridJExtractedLibraries11802898396338342551/OpenIMAJGrabber.so : libv4l2.so.0: cannot open shared object file: No such file or directory
# BridJ: dlopen error when loading /tmp/BridJExtractedLibraries11802898396338342551/OpenIMAJGrabber.so : libv4l2.so.0: cannot open shared object file: No such file or directory
# BridJ: dlopen error when loading /tmp/BridJExtractedLibraries11802898396338342551/OpenIMAJGrabber.so : libv4l2.so.0: cannot open shared o
bject file: No such file or directory
# BridJ: dlopen error when loading /tmp/BridJExtractedLibraries11802898396338342551/OpenIMAJGrabber.so : libv4l2.so.0: cannot open shared object file: No such file or directory
# BridJ: dlopen error when loading /tmp/BridJExtractedLibraries11802898396338342551/OpenIMAJGrabber.so : libv4l2.so.0: cannot open shared object file: No such file or directory
# BridJ: dlopen error when loading /tmp/BridJExtractedLibraries11802898396338342551/OpenIMAJGrabber.so : libv4l2.so.0: cannot open shared object file: No such file or directory
# BridJ: dlopen error when loading /tmp/BridJExtractedLibraries11802898396338342551/OpenIMAJGrabber.so : libv4l2.so.0: cannot open shared object file: No such file or directory
# BridJ: dlopen error when loading /tmp/BridJExtractedLibraries11802898396338342551/OpenIMAJGrabber.so : libv4l2.so.0: cannot open shared object file: No such file or directory

5) Audio output by SourceDataLineWrapper - no devices found.
6) COM-ports (from USB-bridge adapters) - not detected.
 
Last edited:
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
But if to test this app under Linux Mint 21 on a separate 2GB RAM notebook:

1) The same for the same JDK11,
WARNING: package com.sun.glass.ui.win not in javafx.graphics
WARNING: package com.sun.prism.d3d not in javafx.graphics
2) "UTILITY" and "DECORATED" windows - both are OK, but .AlwaysOnTop does not work also
3) No Bluetooth by jBluetooth v.1.01, same error
4) Webcamera of Sarxos library - works OK ! (just by express check)
5) No error for audio by jAudioTrack2 v0.14 lib - but no sound.
6) COM-port is detected as "/dev/ttyUSB0" at two different USB ports, but they cannot be opened (jSerial v 1.32 .Open), error at opening try:
New port /dev/ttyUSB0
Error occurred on line: 40 (usb_serial_device)
jssc.SerialPortException: Port name - /dev/ttyUSB0; Method name - openPort(); Exception type - Port not found.
at jssc.SerialPort.openPort(SerialPort.java:219)
at anywheresoftware.b4j.serial.Serial.Open(Serial.java:118)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:673)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:240)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at jdk.internal.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
a
t anywheresoftware.b4a.BA.raiseEvent2(BA.java:111)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:100)
at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:64)
at peacemaker.orionlab.usb_serial_device._initialize(usb_serial_device.java:67)
at peacemaker.orionlab.usb_devices$ResumableSub_Get_USB_ports.resume(usb_devices.java:1198)
at peacemaker.orionlab.usb_devices._get_usb_ports(usb_devices.java:906)
at peacemaker.orionlab.usb_devices._timports_tick(usb_devices.java:1482)
at jdk.internal.reflect.GeneratedMethodAccessor14.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:629)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:237)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at jdk.internal.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at java
.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:111)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:100)
at anywheresoftware.b4a.objects.Timer$TickTack$1.run(Timer.java:135)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$11(GtkApplication.java:277)
at java.base/java.lang.Thread.run(Thread.java:834)
/dev/ttyUSB0 is skipped

What is instead of jssc.dll under Linux for jSerial ?

--------------
BTW: this my B4J app (using COM-ports, Bluetooth COM-ports, sound-generator, camer and charts) - crossplatform works under Android too, with just 22 pcs of "#if B4A" compilation conditions, and ~130 pcs of "#if B4J" conditions.
But works, actually, all-function.
COM-ports under Android are named with the "/dev/bus/usb/" prefix.

But, Linux cant, as i can see now. But it's needed.
 
Last edited:
Upvote 0

stevel05

Expert
Licensed User
Longtime User
5) No error for audio by jAudioTrack2 v0.14 lib - but no sound.
Apparently sound drivers are not currently installed under WSL, I asked perplexity the question see it's reply here, with a couple of suggestions which I haven't tried.

P.S. I hope the link works, I haven't tried sharing from Perplexity before.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Ah OK, I haven't tried that and am not currently set up to be able to. I'll try it when I get a chance.
Just tried it on Linux Mint 21.3 and the jAudioTrack2 demo worked with audio. I'm pretty sure I haven't loaded anything extra in the past.

Are you trying to play a standard Audio file (44100k 16bit Stereo)?
Do you get sound on anything else?
Have you installed Pipewire? I would be surprised if Java has support for that.
Does your PC have a special soundcard that you might need drivers for?

Further starting points (from Perplexity) here
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
I just used tone generator:

B4X:
Sub Class_Globals
    Private Root As B4XView 'ignore
    Private xui As XUI 'ignore
        
    Private SDL As SourceDataLineWrapper
    Private OutDevice As JavaObject, AudioFormat As JavaObject, SelectedMixerInfo As JavaObject, Devices As List
    Private SampleRateInHz As Float = 44100
    Private SampleSizeInBits As Int = 16
    Private Channels As Int = 2
    Private genOff As Boolean
    Dim MixBuffer(1) As Short
    Dim timFreq As Timer
    
    Dim BC As ByteConverter
End Sub

Sub gene_rate
    SDL.Start

    BC.LittleEndian = True
    Do While genOff=False
        SDL.Write(BC.ShortsToBytes(MixBuffer),0,MixBuffer.Length * 2)
    Loop
    SDL.Flush
    SDL.Stop
End Sub

Sub Prepare_Data1
    Dim Freq1 As Int = IIf(IsNumber(txtLeftFreq.Text), txtLeftFreq.Text, 440)
    Dim Freq2 As Int = IIf(IsNumber(txtRightFreq.Text), txtRightFreq.Text, 1000)
    
    Dim Level1 As Double = IIf(chkMuteLeft.Checked,0, volLeft.Value / 100)
    Dim Level2 As Double = IIf(chkMuteRight.Checked,0, volRight.Value / 100)
    
    Dim LeftPhase As Int = IIf(chkAntiLeft.Checked, 180, 0)
    Dim RightPhase As Int = IIf(chkAntiRight.Checked, 180, 0)
    
    Dim Dur As Double = 0.5 'seconds
    Dim Ampl1 As Int = 32767
    Dim Ampl2 As Int = 32767
    
    Dim L() As Short = generateSinWav(Freq1,Dur,Level1 * Ampl1, LeftPhase)
    Dim R() As Short = generateSinWav(Freq2,Dur,Level2 * Ampl2, RightPhase)
    
    
    Dim MixBuffer(L.Length * 2) As Short
    Dim MixBufferIndex As Int = 0
    
    For i = 0 To L.Length - 1
        MixBuffer(MixBufferIndex) = L(i)
        MixBuffer(MixBufferIndex + 1) = R(i)
        MixBufferIndex = MixBufferIndex + 2
    Next
'    Log(MixBuffer.Length)
End Sub

Sub Array_to_List(arr() As Short) As List
    Dim l As List
    l.Initialize
    For i = 0 To arr.Length - 1
        l.Add(arr(i))
    Next
    Return l
End Sub


Public Sub generateSinWav(Freq As Int, Dur As Double, MaxVal As Double, DegreePhaseShift As Int) As Short()
    Dim Arr(Dur * SampleRateInHz) As Short
    Dim SampleInterval As Double = SampleRateInHz  / Freq
    
    Dim shift As Double = DegreePhaseShift / 180 * cPI
    For i = 0 To Arr.Length - 1
        Dim Angle As Double = (2 * cPI * i) / SampleInterval  - shift
        Arr(i) = Sin(Angle) * MaxVal
    Next
    Return Arr
End Sub

Private Sub Setup_Audio
    Stop_Sound
    'Setup Device names in a B$XCombobox and MixerInfo objects in a list
    Dim MixerInfos As List = jAudioTrack2_Utils.GetDevices(jAudioTrack2_Utils.DEVICETYPE_OUTPUT,"")
    Dim L As List
    L.Initialize
    Dim Devices As List
    Devices.Initialize
    For Each MI As JavaObject In MixerInfos
        'Add the name to the list for the B4xCombobox
        L.add(MI.RunMethod("getName",Null))
        'Add the MixerInfo to the corresponding Devices List
        Devices.Add(MI)
    Next
    If Devices.Size > 0 Then
        Dim SelectedMixerInfo As JavaObject
        SelectedMixerInfo = Devices.Get(0)
        
        Dim AudioFormat As JavaObject
        AudioFormat = jAudioTrack2_Utils.NewAudioFormat(SampleRateInHz, SampleSizeInBits, Channels, True, False)
        Dim OutDevice As JavaObject
        OutDevice = jAudioTrack2_Utils.GetSourceDataLine2(AudioFormat, SelectedMixerInfo)
        Dim SDL As SourceDataLineWrapper
        SDL.Initialize(OutDevice)
    Else
        others.Toast("No ready audio devices found.")
    End If   
End Sub
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Hmm, worked first time on my Laptop with Linux Mint 21.3

I think you must be missing some setup for your soundcard on your system.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Mine is an old laptop, if you have something newer the drivers might not be part of the Linux Mint installation.
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
My generator project with the Threading works at your Linux side ?
 
Upvote 0
Top