【Android 高性能音频】Oboe 音频流打开后 耳机 / 音箱 插拔事件处理 ( 设置 Oboe 音频设备 ID | setDeviceId 函数原型 | AudioStream 音频流 )
文章目錄
- 一、設置 Oboe 音頻設備 ID ( AAudio )
- 二、設置 Oboe 音頻設備 ID ( OpenSL ES)
- 三、oboe :: AudioStreamBuilder :: setDeviceId 函數原型
- 四、oboe :: AudioStream 音頻流
- 五、相關資料
Android 中的 Oboe 音頻流創建時 , 可以在 oboe :: AudioStreamBuilder 中設置 設備 ID , 音頻流一旦創建成功 , 如果是 Android 8.08.08.0 以上的系統 , 則不能修改設備 ID , 必須銷毀當前的 Oboe 音頻流 , 重新使用 oboe :: AudioStreamBuilder 創建音頻流 ;
一、設置 Oboe 音頻設備 ID ( AAudio )
在 Oboe 的文檔中 , oboe :: AudioStreamBuilder 對應的文檔 https://google.github.io/oboe/reference/classoboe_1_1_audio_stream_builder.html 中 , 有音頻設備設置的方法 ;
在 Oboe 音頻流 AudioStream 打開之前 , 可以在音頻流構建器 AudioStreamBuilder 中設置一個音頻設備 ;
查看 AudioStreamBuilder * oboe :: AudioStreamBuilder :: setDeviceId ( int32_t deviceId ) 對應文檔 ,
給定一個音頻設備 ID 編號 , 向特定的音頻輸入或輸出設備請求一個音頻流 ;
在大多數的情況下 , 系統會自動選擇設備 , 就是當前主設備 , 當手機沒有插入耳機 / 音箱時 , 默認是手機的揚聲器 , 當插入 耳機 / 音箱 時 , 默認是插入的 耳機 / 音箱 作為當前的音頻設備 ;
該 setDeviceId ( int32_t deviceId ) 方法的默認設置的值為 kUnspecified , 設置該值的含義就是由系統自動選擇當前的主設備 ;
具體的 設備 ID 值 , 可以調用 Java 的 AudioManager.getDevicees 方法獲取 , 返回 AudioDeviceInfo[] 數組 , 其中就包含了 設備 ID 值 ;
一般情況下是 內置揚聲器 ( 大 ) , 和 內置揚聲器 ( 小 , 打電話通話時的揚聲器 ) , 如果插上耳機 / 音箱 , 則出現第三個外接音頻設備選項 ;
二、設置 Oboe 音頻設備 ID ( OpenSL ES)
如果 Android 系統的版本低于 8.08.08.0 , 則默認使用 OpenSL ES 播放器 , 該播放器不能設置設備的 ID , 系統會自動選擇默認的設備 ;
如果插拔 耳機/音箱 , 會自動進行切換 ;
三、oboe :: AudioStreamBuilder :: setDeviceId 函數原型
AudioStreamBuilder * oboe :: AudioStreamBuilder :: setDeviceId ( int32_t deviceId ) 函數原型 :
/*** Request a stream to a specific audio input/output device given an audio device ID.** In most cases, the primary device will be the appropriate device to use, and the* deviceId can be left kUnspecified.** On Android, for example, the ID could be obtained from the Java AudioManager.* AudioManager.getDevices() returns an array of AudioDeviceInfo[], which contains* a getId() method (as well as other type information), that should be passed* to this method.*** Note that when using OpenSL ES, this will be ignored and the created* stream will have deviceId kUnspecified.** @param deviceId device identifier or kUnspecified* @return pointer to the builder so calls can be chained*/AudioStreamBuilder *setDeviceId(int32_t deviceId) {mDeviceId = deviceId;return this;}四、oboe :: AudioStream 音頻流
Oboe 音頻流類 oboe :: AudioStream , 功能很單一 , 控制音頻的開始 , 暫停 , 停止 等功能 , 獲取音頻播放時的相關參數 , 沒有與設備相關的任何操作 ;
五、相關資料
Oboe GitHub 主頁 : GitHub/Oboe
-
① 簡單使用 : Getting Started
-
② Oboe 全指南 : Full Guide To Oboe
-
③ Oboe API 參考 : API reference
-
④ Android 音頻框架發展 : Android audio history
Oboe API 參考 :
-
API 索引 : https://google.github.io/oboe/reference/namespaceoboe.html
-
Oboe 音頻流創建器 : https://google.github.io/oboe/reference/classoboe_1_1_audio_stream_builder.html
-
Oboe 音頻流 : https://google.github.io/oboe/reference/classoboe_1_1_audio_stream.html
-
Oboe 音頻流回調接口 : https://google.github.io/oboe/reference/classoboe_1_1_audio_stream_callback.html
總結
以上是生活随笔為你收集整理的【Android 高性能音频】Oboe 音频流打开后 耳机 / 音箱 插拔事件处理 ( 设置 Oboe 音频设备 ID | setDeviceId 函数原型 | AudioStream 音频流 )的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【Android 安装包优化】使用 li
- 下一篇: 【Android 高性能音频】Oboe