Android Question Check Runmethod is done

AHilberink

Active Member
Licensed User
Longtime User
Hi,

I am using Runmethod to play a ringtone:
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim rt,jo, jo2 As JavaObject
    Dim u As Uri
    Dim rm As RingtoneManager
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    rt = getRingtone
    Activity.LoadLayout("ringtone")
    PlayRingtone
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub getRingtone As JavaObject
    jo.InitializeStatic("android.media.RingtoneManager")
    jo2.InitializeContext
    Dim u As Uri
    u.Parse(rm.GetDefault(rm.TYPE_ALARM))
    'u.Parse()
    Dim rt As JavaObject
    rt.InitializeContext
    rt = jo.RunMethodJO("getRingtone", Array(jo2, u))
    Return rt
End Sub

Sub PlayRingtone
    rt.RunMethod("play", Null)
End Sub

Sub StopRingtone
    rt.RunMethod("stop", Null)
End Sub


Sub Stopmelding_Click
    StopRingtone
    Activity.Finish
End Sub

Is it possible to check whenever the rt.RunMethod("play", Null) has finished playing?
I want to close this activity after the alarm has played completely.

Now it is playing and only the Stopmelding button will close the activity.

Best regards,
André
 

AHilberink

Active Member
Licensed User
Longtime User
Hi Misterbates,

Thanks for your reply.

When do I call:
B4X:
rt.RunMethod("isPlaying", Null)

This is not an event, it is just a call to a status.
What I look for is a way to trigger when the playing is done, like a callback event.

Best regards,
André
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
create a timer with a interval of 100 ms or so. Check the status inside the timer-tick... raise a callsub when playing is finished (isPlaying = false)...
 
Upvote 0

Misterbates

Active Member
Licensed User
I don't know that you're going to find a callback event. In which case you have two options:
1) Code a loop that checks IsPlaying and if true, calls sleep(nnn) to resume after nnn milliseconds
2) Setup a timer that checks IsPlaying every nnn milliseconds

[Edit] @DonManfred beat me to it ;-)
 
Upvote 0
Top