Frage

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);
}
War es hilfreich?

Lösung

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

Andere Tipps

Use this one, For using Current System Volume.

ToneGenerator toneG = new ToneGenerator(AudioManager.STREAM_SYSTEM, 100);
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top