B4J Question Beep in CustomView

Guenter Becker

Active Member
Licensed User
Change your code to:
B4X:
Sub Beep
    Dim jo As JavaObject = Me
    jo.RunMethod("beep", Null)
End Sub

#if Java
public static void beep() {
    java.awt.Toolkit.getDefaultToolkit().beep();
}
#End If
Hello,
I used exactly the published code inside a CustomView (XUI) class. The code works but there is not sound. Why?
 

LucaMs

Expert
Licensed User
Longtime User
inside a CustomView (XUI) class
Are you modifying the CustomListView source code? (Nothing negative, it's allowed; I'm just asking to make sure I understand correctly.)

Anyway, I think one of the first things to do when debugging is to write lots of logs; in this case, to verify that Sub Beep is actually being called by the rest of your project.

I'm also wondering if inline-java is necessary; is it possible there's no library for "playing" a beep (I don't remember, I'll have to look)?
Or maybe you don't want to use one?
 
Upvote 0

Guenter Becker

Active Member
Licensed User
Are you modifying the CustomListView source code? (Nothing negative, it's allowed; I'm just asking to make sure I understand correctly.)

Anyway, I think one of the first things to do when debugging is to write lots of logs; in this case, to verify that Sub Beep is actually being called by the rest of your project.

I'm also wondering if inline-java is necessary; is it possible there's no library for "playing" a beep (I don't remember, I'll have to look)?
Or maybe you don't want to use one?
Thank you for your response,
I'm developing a CustomView and one of its feature is to play a beep called by other Sub.
Due to developing in B4J there is no lib available to do so except you use a mediaplayer/streaming. Therefor in the B4J Forum erel published the shown code. I tested also the solutions of alternatives without Java code but they throw an error that they can't load the named AWT Toolkit.
Erels Code is firing no error but not sound. Checked PC sound is OK.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Checked Windows Sound settings?

Sound
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
throw an error that they can't load the named AWT Toolkit.
Are you seeing this error:
B4X:
java.lang.IllegalAccessException: class anywheresoftware.b4j.object.JavaObject cannot access class sun.awt.windows.WToolkit (in module java.desktop) because module java.desktop does not export sun.awt.windows to unnamed module @7907ec20

Using StarDust's code, I get this error when using JDK 19 but works for JDK 11 and JDK 14.

If I use Erel's inline Java code, it works for all 3 JDKs.
 
Upvote 0

Guenter Becker

Active Member
Licensed User
Youre right, I found other solution by using jAudioClip that works
 
Upvote 0
Top