Question

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);
}
Was it helpful?

Solution

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...

OTHER TIPS

Use this one, For using Current System Volume.

ToneGenerator toneG = new ToneGenerator(AudioManager.STREAM_SYSTEM, 100);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top