B4J Question How to send parameters to a inline JAVA code.

Midimaster

Active Member
Licensed User
I'm very happy about B4A and now try to do my first step in B4J. I need a library for AudioStreaming and found a Class PlayDataAudio.Bas. The class wraps some java functions, so I can call them from my code. I can send Byte-Arrays to this third party code. The speaker sounds as expected. But for one function I would need more parameter to change.

But I have no idea on how to change the call of the JAVA-function....

I would need to change HERTZ and SAMPLE-DEPTH and NUMBER OF CHANNELS during runtime.

B4X:
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
    nativeMe = Me
    nativeMe.RunMethod( "initialaudio", Null)
End Sub
...


#IF JAVA
import javax.sound.sampled.*;

    SourceDataLine _speaker;

    public void initialaudio() throws LineUnavailableException{
        //  specifying the audio format
        AudioFormat _format = new AudioFormat(44100.F,// HERTZ
                16,     //  SAMPLE-DEPTH
                1,      // NUMBER OF CHANNELS
                true,   // Is Signed?
                false   // Is Big Endian?
        );

        //  creating the DataLine Info For the speaker format
        DataLine.Info speakerInfo = new DataLine.Info(SourceDataLine.class, _format);

        //  getting the mixer For the speaker
        _speaker = (SourceDataLine) AudioSystem.getLine(speakerInfo);
        _speaker.open(_format);
    }
.....

What does this "F" mean beyond the 44100???

I tried this, but it throws an error :


Public Sub Initialize
dim Hertz as Int=44100
...
nativeMe.RunMethod( "initialaudio", Hertz)
End Sub
....

#IF JAVA
...
public void initialaudio(int hertz) throws LineUnavailableException{
...
...
 

Midimaster

Active Member
Licensed User
Declaring float Variable
thanks! got it!

B4X:
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
    Dim Hertz as Float = 44100
    Dim Depth as Int=16
    nativeMe = Me
    nativeMe.RunMethod( "initialaudio", array(Hertz, Depth))
End Sub
...


#IF JAVA
...
    public void initialaudio(float hertz, int depth) throws LineUnavailableException{
        //  specifying the audio format
        AudioFormat _format = new AudioFormat(hertz,// HERTZ
                depth,     //  SAMPLE-DEPTH
                1,      // NUMBER OF CHANNELS
                true,   // Is Signed?
                false   // Is Big Endian?
        );
.....
 
Upvote 0
Top