Beep like function?

hackhack

Active Member
Licensed User
Longtime User
Is there a way to play a beep sound without having to use external files? (like wav or midi)
 

hackhack

Active Member
Licensed User
Longtime User
Pity, it increases size.

Unless there are sound files in Android one can use? You know like Windows installs a set of beeps and pings for use in user interface?
 
Upvote 0

hackhack

Active Member
Licensed User
Longtime User
Actually I read that one can use the ringtones, like

B4X:
MediaPlayer player = MediaPlayer.create(this,
    Settings.System.DEFAULT_RINGTONE_URI);
player.start();

Though more relevant would perhaps be DEFAULT_NOTIFICATION_URI - now to see if this works in b4a :)
 
Upvote 0

hackhack

Active Member
Licensed User
Longtime User
Hm, I see on both my phone and tablet in

B4X:
/system/media/audio/

There are several audio files already in place.
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
Currently you will not be able to use it with Basic4android.
Ahem! actually ...

B4X:
Sub Btn1_Click
   Dim Obj1 As Reflector
   Obj1.Target = Obj1.CreateObject("android.provider.Settings$System")
   Obj1.Target = Obj1.GetField("DEFAULT_NOTIFICATION_URI")
   Dim args(2) As Object
   args(0) = Obj1.GetContext
   args(1) = Obj1.Target
   Dim types(2) As String
   types(0) = "android.content.Context"
   types(1) = "android.net.Uri"
   Obj1.Target = Obj1.RunStaticMethod("android.media.MediaPlayer", "create", args, types)
   Obj1.RunMethod("start")
End Sub
 
Upvote 0

hackhack

Active Member
Licensed User
Longtime User
Better add some tags so people can find it if they search: play default notification sound audio

Ahem! actually ...

B4X:
Sub Btn1_Click
   Dim Obj1 As Reflector
   Obj1.Target = Obj1.CreateObject("android.provider.Settings$System")
   Obj1.Target = Obj1.GetField("DEFAULT_NOTIFICATION_URI")
   Dim args(2) As Object
   args(0) = Obj1.GetContext
   args(1) = Obj1.Target
   Dim types(2) As String
   types(0) = "android.content.Context"
   types(1) = "android.net.Uri"
   Obj1.Target = Obj1.RunStaticMethod("android.media.MediaPlayer", "create", args, types)
   Obj1.RunMethod("start")
End Sub
 
Upvote 0

hackhack

Active Member
Licensed User
Longtime User
Funny though, it crashes the emulator with a java.lang.NullPointerException but works fine on the phone.
 
Upvote 0

MDEnt

Member
Licensed User
Longtime User
Ahem! actually ...

B4X:
Sub Btn1_Click
   Dim Obj1 As Reflector
   Obj1.Target = Obj1.CreateObject("android.provider.Settings$System")
   Obj1.Target = Obj1.GetField("DEFAULT_NOTIFICATION_URI")
   Dim args(2) As Object
   args(0) = Obj1.GetContext
   args(1) = Obj1.Target
   Dim types(2) As String
   types(0) = "android.content.Context"
   types(1) = "android.net.Uri"
   Obj1.Target = Obj1.RunStaticMethod("android.media.MediaPlayer", "create", args, types)
   Obj1.RunMethod("start")
End Sub
Not much experience with reflection & system settings, but is it possible to use code similar to this example to setfield (assign default notification) instead of getfield to read it?
 
Upvote 0
Top