Search code examples
androidfiremonkeydelphi-xe7

How do I make a beep sound in Android using Delphi and the API?


After having a look at the Androidapi.JNI.Media.pas, I coded the following procedure:

uses
  Androidapi.JNIBridge,
  AndroidApi.JNI.Media;

procedure Sound(ADuration: Integer);

implementation

procedure Sound(ADuration: Integer);
var
  Volume: Integer;
  StreamType: Integer;
  ToneType: Integer;
  ToneGenerator: JToneGenerator;
begin

  Volume := TJToneGenerator.JavaClass.MAX_VOLUME;

  StreamType := ?
  ToneType := TJToneGenerator.JavaClass.TONE_DTMF_0;

  ToneGenerator := TJToneGenerator.JavaClass.init(StreamType, Volume);
  ToneGenerator.startTone(ToneType, ADuration);

end;

but I can't figure out how to set a value for the StreamType? Thanks


Solution

  • The stream type identify the stream on which the beep must be played. It is an integer between 0 and 4 :

    • STREAM_VOICE_CALL (0)
    • STREAM_SYSTEM (1)
    • STREAM_RING (2)
    • STREAM_MUSIC(3)
    • STREAM_ALARM(4)