check if device is playing sound

BrunoPT

New Member
Hi, i am new in b4a and i need to know how do i check if my phone is playing sound from other apps.
It's possible to do that?

PS:Sorry for the english, i am portuguese.
 

stevel05

Expert
Licensed User
Longtime User
This code will tell you if Music is playing, although you won't be able to do anything about music playing from other apps as you won't have access to the player instance to turn it off. The best you could do is to turn the volume down.

If you just want to check before playing your own sounds, then this should work fine.

It uses the AudioManager API, and requires the Reflection library.

B4X:
   Dim R As Reflector
   R.Target=R.GetContext
   R.Target=R.RunMethod2("getSystemService","audio","java.lang.String")
   Label1.Text=R.RunMethod("isMusicActive")
 
Last edited:
Upvote 0
Top