Android/App개발2010. 4. 19. 16:39
볼륨키로 조절시 어떤때는 ringer볼륨, 어떤때는 music볼륨등 다르게 조절되는것을 볼수있다.
이 때 이값은 어떻게 결정될까?

AudioService의 getActiveStreamType(int suggestedStreamType)함수에 의해 요구한 볼륨조절값을 참조하여 현재 시스템의 상태에 따른 볼륨조절 믹서 종류를 구분하여 준다.

    private int getActiveStreamType(int suggestedStreamType) {
        boolean isOffhook = false;
        try {
            ITelephony phone = ITelephony.Stub.asInterface(ServiceManager.checkService("phone"));
            if (phone != null) isOffhook = phone.isOffhook();
        } catch (RemoteException e) {
            Log.w(TAG, "Couldn't connect to phone service", e);
        }

        if (AudioSystem.getForceUse(AudioSystem.FOR_COMMUNICATION) == AudioSystem.FORCE_BT_SCO) {
            // Log.v(TAG, "getActiveStreamType: Forcing STREAM_BLUETOOTH_SCO...");
            return AudioSystem.STREAM_BLUETOOTH_SCO;
        } else if (isOffhook) {
            // Log.v(TAG, "getActiveStreamType: Forcing STREAM_VOICE_CALL...");
            return AudioSystem.STREAM_VOICE_CALL;
        } else if (AudioSystem.isMusicActive()) {
            // Log.v(TAG, "getActiveStreamType: Forcing STREAM_MUSIC...");
            return AudioSystem.STREAM_MUSIC;
        } else if (suggestedStreamType == AudioManager.USE_DEFAULT_STREAM_TYPE) {
            // Log.v(TAG, "getActiveStreamType: Forcing STREAM_RING...");
            return AudioSystem.STREAM_RING;
        } else {
            // Log.v(TAG, "getActiveStreamType: Returning suggested type " + suggestedStreamType);
            return suggestedStreamType;
        }
    }

함수의 구현내용을 살펴보면...
BT사용중이면 BT볼륨  -> Call중이면 VoiceCall볼륨 -> 음악재생중이면 Music 볼륨 -> 디폴트는 Ringer볼륨 의 순서로 결정된다.




Posted by 삼스