Вопрос

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);
}
Это было полезно?

Решение

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

Другие советы

Use this one, For using Current System Volume.

ToneGenerator toneG = new ToneGenerator(AudioManager.STREAM_SYSTEM, 100);
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top