[fpc-pascal] JNI/Android: Java events calling pascal code
patspiper
patspiper at gmail.com
Tue Apr 22 18:15:12 CEST 2014
On 22/04/14 18:36, leledumbo wrote:
>> My question is if it can be done without a java wrapper class as this
> would make android programming much easier (unless I have misunderstood
> your reply).
>
> Perhaps I misunderstood your question in the first place. Could you instead
> draw a diagram (flowchart?) and emphasize (red circle or something) the part
> you wish to create?
Let's consider a Lazarus TTimer. You set its interval, assign a method
for the OnTimer event, and set enabled to True. Once the interval is
over, OnTimer will fire and call the assigned method. Note that we did
not touch the TTimer component's code.
Now to the java media player: You assign a pascal method to the
OnCompetion event (the question is how), and start the player
(pascal/jni). Once the song is over, OnCompletion will fire and call the
assigned pascal method.
Pascal/JNI pseudo code:
procedure Play;
begin
jmediaplayer.Oncompletion := @MyOnCompletion; // how?
jmediaplayer.start; // the actual code needs to get the jclass,
jmethodID and make the start call (no java code involved)
end;
procedure MyOnCompletion(AEnv: Penv; aObj: jObject)
begin
ShowMessage('Song has ended');
end;
I hope this is clearer.
Stephano
More information about the fpc-pascal
mailing list