Class Sound

java.lang.Object
de.gurkenlabs.litiengine.sound.Sound

public final class Sound
extends java.lang.Object
This class implements all required functionality to load sounds from the file system and provide a stream that can later on be used for the sound playback.
  • Constructor Summary

    Constructors 
    ConstructorDescription
    Sound​(java.io.InputStream is, java.lang.String name)
    Creates a new Sound instance by the specified file path.
  • Method Summary

    Modifier and TypeMethodDescription
    javax.sound.sampled.AudioFormatgetFormat()
    Gets the audio format of this sound instance.
    java.lang.StringgetName()
    Gets the name of this instance that is used to uniquely identify the resource of this sound.
    byte[]getRawData()
    Gets the raw data of this sound as byte array.
    java.lang.StringtoString() 

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Sound

      public Sound​(java.io.InputStream is, java.lang.String name) throws java.io.IOException, javax.sound.sampled.UnsupportedAudioFileException
      Creates a new Sound instance by the specified file path. Loads the sound data into a byte array and also retrieves information about the format of the sound file. Note that the constructor is private. In order to load files use the static Resources.sounds().get(String) method.
      Parameters:
      is - The input stream to load the sound from.
      name - The name of this sound file.
      Throws:
      java.io.IOException - If something went wrong loading the file
      javax.sound.sampled.UnsupportedAudioFileException - If the audio format is not supported
  • Method Details

    • getFormat

      public javax.sound.sampled.AudioFormat getFormat()
      Gets the audio format of this sound instance.
      Returns:
      The audio format of this instance.
    • getName

      public java.lang.String getName()
      Gets the name of this instance that is used to uniquely identify the resource of this sound.
      Returns:
      The name of this sound.
    • getRawData

      public byte[] getRawData()
      Gets the raw data of this sound as byte array.

      This is used during resource serialization.

      Returns:
      The raw data of this sound as byte array.
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.Object