Je suis un peu nouveau pour Android Je travailleerror I2S1: Impossible de lire à partir du périphérique de sortie uniquement (opération non autorisée) (code 1)
- principalement sur micro Adafruit i2S
- aussi microphone USB typique avec des choses Android sur Raspberry pi.
La documentation Android indique qu'elle prend en charge le micro USB depuis Preview 2, mais je n'ai trouvé aucun exemple.
https://developer.android.com/things/preview/releases.html
Je suis sur le micro i2S pour l'instant et coincé ici.
code
// 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);
}
Problème
À la ligne:
mDevice.read()
moniteur android dit
I2S1 error: Cannot read from output-only device (Operation not permitted) (code 1)
Puis-je obtenir de l'aide?