Class AudioPlayer

All Implemented Interfaces:
Behavior, Renderable, Closeable, AutoCloseable

public class AudioPlayer extends ComponentBehavior
The AudioPlayer class is a component behavior that allows for playing, pausing, and manipulating audio clips in a Yield application.
  • Constructor Details

    • AudioPlayer

      public AudioPlayer()
  • Method Details

    • play

      public void play()
      This function plays the audio clip using the application's audio manager.
    • loop

      public void loop()
      This function loops audio using the application's audio manager.
    • reset

      public void reset()
      The "reset" function sets the position to 0.
    • pause

      public void pause()
      This function pauses the audio clip using the application's audio manager.
    • close

      public void close() throws IOException
      Description copied from class: ComponentBehavior
      Called when the behavior is closed.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class ComponentBehavior
      Throws:
      IOException - If an I/O error occurs.
    • position

      public double position()
      This function returns the position of the audio player.
      Returns:
      The current position of the audio clip in seconds.
    • setPosition

      public AudioPlayer setPosition(double position)
      This function sets the position of the audio player using the application's audio manager.
      Parameters:
      position - The new position of the audio playback in seconds.
      Returns:
      The AudioPlayer instance for method chaining.
    • length

      public double length()
      This function returns the length of the audio clip.
      Returns:
      The length of the audio clip in seconds.
    • audioClip

      public FileInput audioClip()
      The function returns the audio clip file input.
      Returns:
      The FileInput object representing the audio clip.
    • setAudioClip

      public AudioPlayer setAudioClip(FileInput audioClip)
      This function sets the audio clip and unloads any previous audio clip if it exists.
      Parameters:
      audioClip - The new audio file to be set for the audio player.
      Returns:
      The AudioPlayer instance for method chaining.
    • clipRef

      public Object clipRef()
      The function returns the reference to a clip object.
      Returns:
      The reference to the clip object.
    • setClipRef

      public AudioPlayer setClipRef(Object clipRef)
      This function sets the value of the clipRef variable.
      Parameters:
      clipRef - The new value for the clipRef variable.
      Returns:
      The AudioPlayer instance for method chaining.
    • pan

      public double pan()
      The function returns the value of the "pan" variable as a double data type.
      Returns:
      The current stereo panning value of the audio.
    • setPan

      public AudioPlayer setPan(double pan)
      This function sets the pan of an audio object and throws an exception if the pan is not within the valid range.
      Parameters:
      pan - The new stereo panning value of the audio. It should be between -1.0 (fully panned to the left) and 1.0 (fully panned to the right).
      Returns:
      The AudioPlayer instance for method chaining.
    • playing

      public boolean playing()
      This function returns a boolean value indicating whether the audio is currently playing or not.
      Returns:
      True if the audio is currently playing, false otherwise.
    • gain

      public double gain()
      The function returns the value of the variable "gain" as a double.
      Returns:
      The current audio gain level.
    • gain

      public void gain(double gain)
      This function sets the gain of the audio player and throws an exception if the gain is not within the valid range.
      Parameters:
      gain - The new audio gain level to be set. It should be between 0.0 (no sound) and 1.0 (maximum volume).