Android Question How to play SoundEffectConstants ?

ducphu

Active Member
Licensed User
Longtime User
Hi all,

Is it possible to play SoundEffectConstants such as android.view.SoundEffectConstants.CLICK ?
 

stevel05

Expert
Licensed User
Longtime User
You can play them using the AudioManager and Javaobject:

B4X:
Dim Effect As Int = 0
    Dim Vol As Float = 1.0
    Dim CTX As JavaObject
    CTX.InitializeContext
    Dim AM As JavaObject = CTX.RunMethod("getSystemService",Array("audio"))
    AM.RunMethod("playSoundEffect",Array(Effect,Vol))

See http://developer.android.com/reference/android/media/AudioManager.html for more information and Available Effect Constants.

Example project attached.

From the documentation, you may need to enable and/or load the sounds. But it works on My Nexus7 with the user setting disabled, So it may not be an issue.
 

Attachments

  • SEExample.zip
    7.7 KB · Views: 200
Last edited:
Upvote 0
Top