Android Question Ringtonemanager: isPlaying

KMatle

Expert
Licensed User
Longtime User
Could someone give me an example how to check if a ringtone is still playing (using the ringtonemanager)?

B4X:
rm.Play(rm.GetDefault(rm.TYPE_ALARM))

There is a thread about it but not an example with JO:

B4X:
Dim jo As JavaObject
jo.InitializeStatic("android.media.RingtoneManager")
Log(jo.RunMethod("isPlaying",Null))

will throw a "java.lang.RuntimeException: Method: isPlaying not found in: android.media.RingtoneManager" exception
 

JordiCP

Expert
Licensed User
Longtime User
Can't test it now, but the method "isPlaying" does not belong to the android ringtoneManager but to the ringtone being played

So instead of initializing JO to the ringtonemanager, you should initialize it to the Ringtone from the uri and then apply the isPlaying method
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You will need to play the ringtone with the code I posted here: https://www.b4x.com/android/forum/threads/default-message-sound.56476/#post-355337

The last line is:
B4X:
 jo.RunMethodJO("getRingtone", Array(jo2, u)).RunMethod("play", Null)
Change it to:
B4X:
ringtone = jo.RunMethodJO("getRingtone", Array(jo2, u)) 'ringtone is a global JavaObject
ringtone.RunMethod("play", Null)

Now you can call isPlaying with:
B4X:
ringtone.RunMethod("isPlaying", Null)
 
Upvote 0

kisoft

Well-Known Member
Licensed User
Longtime User
How to stop playing the sound in this method?. I'm using this code but it does not work.

ringtone.RunMethod("stop", Null)
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Always create a new thread in the question forum. For EACH question you have.
 
Upvote 0

AHilberink

Active Member
Licensed User
Longtime User
You will need to play the ringtone with the code I posted here: https://www.b4x.com/android/forum/threads/default-message-sound.56476/#post-355337

The last line is:
B4X:
jo.RunMethodJO("getRingtone", Array(jo2, u)).RunMethod("play", Null)
Change it to:
B4X:
ringtone = jo.RunMethodJO("getRingtone", Array(jo2, u)) 'ringtone is a global JavaObject
ringtone.RunMethod("play", Null)

Now you can call isPlaying with:
B4X:
ringtone.RunMethod("isPlaying", Null)

Hi,

I am using this methode, but I got the message on ringtone object:
java.lang.RuntimeException: Object should first be initialized (JavaObject).

How do I initialized this JavaObject?

Best regards,
André
 
Upvote 0
Top