Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static String loadSoundFromWad(Wad wad, String lumpName) {
- String soundName = wad.getWadFileLocation().getName() + lumpName;
- Lump lump = wad.getLumpByName(lumpName);
- if (lump != null) {
- try{
- // Get bytebuffer from the sound lump in the wad
- ByteBuffer audioByteBuffer = lump.getRawLumpData().getByteBuffer();
- // Create new byte array
- byte[] audioBuffer = new byte[audioByteBuffer.remaining()];
- // Fill byte array with wad buffer data
- audioByteBuffer.get(audioBuffer);
- // Flip the buffer for reading
- audioByteBuffer.flip();
- // Create Inputstream based on Bytebuffer
- InputStream audioStream = new ByteBufferBackedInputStream(audioByteBuffer);
- // Buffer the Inputstream
- BufferedInputStream bufferedAudioStream = new BufferedInputStream(audioStream);
- // Create AudioInputStream from BufferedInputStream
- AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(bufferedAudioStream);
- // Send to sound system
- soundSystem.loadSound(audioBuffer, audioInputStream.getFormat(), soundName);
- return soundName;
- }catch(Exception e) {
- e.printStackTrace();
- }
- }
- return null;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement