我有點新到Android我工作I2S1錯誤:不能只從輸出設備讀取(不允許的操作)(代碼1)
- 大多I2S Adafruit的麥克風
- 也典型的USB麥克風 與Raspberry Pi上的Android事物。
Android文檔稱自從Preview 2以來它支持USB麥克風,但我找不到任何示例。
https://developer.android.com/things/preview/releases.html
所以我在I2S麥克風現在困在這裏。
代碼
// I2S Device Name
private static final String I2S_DEVICE_NAME = "I2S1";
private static final AudioFormat AUDIO_FORMAT_STEREO =
new AudioFormat.Builder()
.setChannelMask(AudioFormat.CHANNEL_IN_STEREO)
.setEncoding(AudioFormat.ENCODING_PCM_16BIT)
.setSampleRate(44100)
.build();
private I2sDevice mDevice;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String str = "";
// Attempt to access the I2C device
try {
PeripheralManagerService manager = new PeripheralManagerService();
mDevice = manager.openI2sDevice(I2S_DEVICE_NAME, AUDIO_FORMAT_STEREO, I2sDevice.PCM_FORMAT_16_BIT);
} catch (IOException e) {
Log.w(TAG, "Unable to access I2S device", e);
}
// Set up the audio playback sink
int bufferSize = AudioTrack.getMinBufferSize(
AUDIO_FORMAT_STEREO.getSampleRate(),
AUDIO_FORMAT_STEREO.getChannelMask(),
AUDIO_FORMAT_STEREO.getEncoding());
str += String.valueOf(bufferSize) + " ";
// Transfer data from input to output
ByteBuffer buffer = ByteBuffer.allocate(bufferSize);
try{
int read = mDevice.read(buffer, bufferSize);
str += String.valueOf(read);
} catch (IOException e) {
Log.w(TAG, "Unable to access I2S1 device", e);
}
TextView myText = (TextView) findViewById(R.id.mytextview);
myText.setText(str);
}
問題
在行:
mDevice.read()
Android的顯示器說
I2S1 error: Cannot read from output-only device (Operation not permitted) (code 1)
我可以得到任何幫助嗎?