Class Sound

java.lang.Object
com.iragui.objects.Sound
All Implemented Interfaces:
Serializable

public class Sound extends Object implements Serializable
Represents a sound resource loaded from a ByteBuffer.

This class wraps OpenAL buffer and source handling, making it easy to load, play, stop, and manage sounds (such as music or sound effects). Sounds can be configured to loop and optionally start playing immediately.

Remember to call delete() when you are finished with the sound to free OpenAL resources.

See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Sound(ByteBuffer bytes, boolean loops, boolean playOnStart, String name)
    Loads a new sound from Vorbis-encoded data.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Deletes this sound and frees its OpenAL buffer and source.
    boolean
     
    boolean
     
    void
    Pauses the sound (implemented by stopping playback).
    void
    Plays the sound if it is not already playing.
    void
    Forces the sound to loop and starts playing.
    boolean
     
    void
    Resumes the sound if it was paused or stopped.
    void
    Stops the sound immediately if it is playing.
    void
    Stops the sound if it's playing, then plays it again from the start.
    void
    Allows the sound to finish its current loop, then stop.

    Methods inherited from class java.lang.Object

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

    • Sound

      public Sound(ByteBuffer bytes, boolean loops, boolean playOnStart, String name)
      Loads a new sound from Vorbis-encoded data.
      Parameters:
      bytes - The raw audio data in Vorbis format.
      loops - Whether this sound should loop when played.
      playOnStart - Whether this sound should start playing automatically when created.
      name - The name of the sound (used in error messages).
  • Method Details

    • loops

      public boolean loops()
      Returns:
      whether this sound is configured to loop.
    • delete

      public void delete()
      Deletes this sound and frees its OpenAL buffer and source.

      Must be called when the sound is no longer needed.

    • stopAndPlay

      public void stopAndPlay()
      Stops the sound if it's playing, then plays it again from the start.
    • play

      public void play()
      Plays the sound if it is not already playing. If the sound was stopped, it restarts from the beginning.
    • stop

      public void stop()
      Stops the sound immediately if it is playing.
    • stopAtNextLoop

      public void stopAtNextLoop()
      Allows the sound to finish its current loop, then stop.
    • playForceLoop

      public void playForceLoop()
      Forces the sound to loop and starts playing.
    • playOnStart

      public boolean playOnStart()
      Returns:
      whether this sound should be flagged as playOnStart.
    • isPlaying

      public boolean isPlaying()
      Returns:
      whether this sound is currently playing.
    • pause

      public void pause()
      Pauses the sound (implemented by stopping playback).
    • resume

      public void resume()
      Resumes the sound if it was paused or stopped.