문제

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