Tiralka
Tiralka

Reputation: 41

Android volume of a beep generated by ToneGenerator

I am using the ToneGenarator in order to play a continuous beep. The problem is that the volume is far too low!

We can't hear anything when the volume is lower than 8. And with the maximum volume, it is not loud at all...

Is it a limitation of the DTMF sound or am I doing something wrong?

Here is the code:

private final int TONE_TYPE = ToneGenerator.TONE_DTMF_5;
private final int STREAM = AudioManager.STREAM_MUSIC;
private final int DOT_TIME = 3;

public SoundManager(Activity anActivity) {
    audio = (AudioManager) anActivity
            .getSystemService(Context.AUDIO_SERVICE);
    generator = new ToneGenerator(STREAM,
            audio.getStreamMaxVolume(STREAM));
}

private void playBeep() {
    generator.startTone(TONE_TYPE, DOT_TIME);
}

Upvotes: 1

Views: 8599

Answers (2)

user9751617
user9751617

Reputation:

Use this one, For using Current System Volume.

ToneGenerator toneG = new ToneGenerator(AudioManager.STREAM_SYSTEM, 100);

Upvotes: 2

Tiralka
Tiralka

Reputation: 41

I found where the problem was:

ToneGenerator takes a volume between 0 and 100, while the stream volume is between 0 and 15. Thus, audio.getStreamMaxVolume(STREAM) gives 15 out of 100, it is low...

Upvotes: 1

Related Questions