Play sound directly from byte array - Java
问题 I'm trying to play a sound that is stored as a byte-array using the following method: byte[] clickSamples = getAudioFileData("sound.wav"); ByteBuffer buffer = ByteBuffer.allocate(bufferSize*2); int tick = 0; for (int i = 0; i < clickSamples.length; i++) { buffer.putShort((short) clickSamples[i]); tick++; if (tick >= bufferSize/SAMPLE_SIZE) { line.write(buffer.array(), 0, buffer.position()); buffer.clear(); tick = 0; } } It's kind of hard to explain what's going wrong. I'm getting a sound but