Android聲音焦點----從音樂回到Luncher調節音量顯示的是Music的音量

來源:互聯網
上載者:User

標籤:android   焦點   音樂   audio   

聲音的類型有:定義在AudioSystem.java檔案中

/* The default audio stream */public static final int STREAM_DEFAULT = -1;/* The audio stream for phone calls */public static final int STREAM_VOICE_CALL = 0;/* The audio stream for system sounds */public static final int STREAM_SYSTEM = 1;/* The audio stream for the phone ring and message alerts */public static final int STREAM_RING = 2;/* The audio stream for music playback */public static final int STREAM_MUSIC = 3;/* The audio stream for alarms */public static final int STREAM_ALARM = 4;/* The audio stream for notifications */public static final int STREAM_NOTIFICATION = 5;/* @hide The audio stream for phone calls when connected on bluetooth */public static final int STREAM_BLUETOOTH_SCO = 6;/* @hide The audio stream for enforced system sounds in certain countries (e.g camera in Japan) */public static final int STREAM_SYSTEM_ENFORCED = 7;/* @hide The audio stream for DTMF tones */public static final int STREAM_DTMF = 8;/* @hide The audio stream for text to speech (TTS) */public static final int STREAM_TTS = 9;
正常情況下在音、視頻介面調節音量大小的Stream是STREAM_MUSIC,回到Luncher調節的是STREAM_VOICE_CALL,但這個切換有點延遲StreamOverride.sDelayMs,導致退出音、視頻介面後馬上調節,改變的還是STREAM_MUSIC的大小,:

可以修改/frameworks/base/media/java/android/media/AudioService.java檔案

 /**     * For code clarity for getActiveStreamType(int)     * @param delay_ms max time since last STREAM_MUSIC activity to consider     * @return true if STREAM_MUSIC is active in streams handled by AudioFlinger now or     *     in the last "delay_ms" ms.     */    private boolean isAfMusicActiveRecently(int delay_ms) {        return AudioSystem.isStreamActive(AudioSystem.STREAM_MUSIC, delay_ms)                || AudioSystem.isStreamActiveRemotely(AudioSystem.STREAM_MUSIC, delay_ms);    }    private int getActiveStreamType(int suggestedStreamType) {        switch (mPlatformType) {        case PLATFORM_VOICE:            if (isInCommunication()) {                if (AudioSystem.getForceUse(AudioSystem.FOR_COMMUNICATION)                        == AudioSystem.FORCE_BT_SCO) {                    // Log.v(TAG, "getActiveStreamType: Forcing STREAM_BLUETOOTH_SCO...");                    return AudioSystem.STREAM_BLUETOOTH_SCO;                } else {                    // Log.v(TAG, "getActiveStreamType: Forcing STREAM_VOICE_CALL...");                    return AudioSystem.STREAM_VOICE_CALL;                }            } else if (suggestedStreamType == AudioManager.USE_DEFAULT_STREAM_TYPE) {                if (isAfMusicActiveRecently(StreamOverride.sDelayMs)) {                    if (DEBUG_VOL)                        Log.v(TAG, "getActiveStreamType: Forcing STREAM_MUSIC stream active");                    return AudioSystem.STREAM_MUSIC;                    } else {                        if (DEBUG_VOL)                            Log.v(TAG, "getActiveStreamType: Forcing STREAM_RING b/c default");                        return AudioSystem.STREAM_RING;                }            } else if (isAfMusicActiveRecently(0)) {                if (DEBUG_VOL)                    Log.v(TAG, "getActiveStreamType: Forcing STREAM_MUSIC stream active");                return AudioSystem.STREAM_MUSIC;            }            break;        case PLATFORM_TELEVISION:            if (suggestedStreamType == AudioManager.USE_DEFAULT_STREAM_TYPE) {                    // TV always defaults to STREAM_MUSIC                    return AudioSystem.STREAM_MUSIC;            }            break;        default:            if (isInCommunication()) {                if (AudioSystem.getForceUse(AudioSystem.FOR_COMMUNICATION)                        == AudioSystem.FORCE_BT_SCO) {                    if (DEBUG_VOL) Log.v(TAG, "getActiveStreamType: Forcing STREAM_BLUETOOTH_SCO");                    return AudioSystem.STREAM_BLUETOOTH_SCO;                } else {                    if (DEBUG_VOL)  Log.v(TAG, "getActiveStreamType: Forcing STREAM_VOICE_CALL");                    return AudioSystem.STREAM_VOICE_CALL;                }            } else if (AudioSystem.isStreamActive(AudioSystem.STREAM_NOTIFICATION,                    StreamOverride.sDelayMs) ||                    AudioSystem.isStreamActive(AudioSystem.STREAM_RING,                            StreamOverride.sDelayMs)) {                if (DEBUG_VOL) Log.v(TAG, "getActiveStreamType: Forcing STREAM_NOTIFICATION");                return AudioSystem.STREAM_NOTIFICATION;            } else if (suggestedStreamType == AudioManager.USE_DEFAULT_STREAM_TYPE) {                if (isAfMusicActiveRecently(StreamOverride.sDelayMs)) {                    if (DEBUG_VOL) Log.v(TAG, "getActiveStreamType: forcing STREAM_MUSIC");                    return AudioSystem.STREAM_MUSIC;                } else {                    if (DEBUG_VOL) Log.v(TAG,                            "getActiveStreamType: using STREAM_NOTIFICATION as default");                    return AudioSystem.STREAM_NOTIFICATION;                }            }            break;        }        if (DEBUG_VOL) Log.v(TAG, "getActiveStreamType: Returning suggested type "                + suggestedStreamType);        return suggestedStreamType;    }
把isAfMusicActiveRecently(StreamOverride.sDelayMs) 改為: isAfMusicActiveRecently(0) 或一個小的值。


Android聲音焦點----從音樂回到Luncher調節音量顯示的是Music的音量

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.