Class Tailwind

java.lang.Object
com.jackmeng.halcyoninae.tailwind.Tailwind
All Implemented Interfaces:
Audio
Direct Known Subclasses:
TailwindPlaylist

public class Tailwind extends Object implements Audio
The official adapted audio framework for the Halcyon Program.

This framework is licensed under the GPL-2.0 license. If you are to incorporate this in your own program, you must follow the addendums of the GPL-2.0 license.

This engine is multi-use meaning it is much more efficient for you to have one instance of this class and use it throughout your program. Reuse of this player is done by closing and opening again.

An opening call while it is already opened will cause the stream to close forcefully. It is suggested for the user to strongly check if the stream is open beforehand and handle it themselves accordingly, instead of letting open(File) handle it itself.

A good system to implement is a playlist feature where data is constantly fed into the player once the old stream ends. This can be done via listener and by handling the open and play functions accordingly.

For different circumstances it should be noted that the usage of an opening buffer is not used and every thing is gathered from AudioFormat. This results in less overhead and less cpu usage.

Implementation for different audio formats is provided by the AudioUtil class.

Since:
3.1
Author:
Jack Meng
  • Field Details

  • Constructor Details

    • Tailwind

      public Tailwind()
  • Method Details

    • handleException

      private void handleException(Exception e)
      Parameters:
      e -
    • setDynamicAllocation

      public void setDynamicAllocation(boolean s)
      Parameters:
      s -
    • getPipelineMethod

      public TailwindPipelineMethod getPipelineMethod()
      Returns:
      TailwindPipelineMethod
    • setPipelineMethod

      public void setPipelineMethod(TailwindPipelineMethod pipeline) throws TailwindThrowable
      Parameters:
      pipeline -
      Throws:
      TailwindThrowable
    • isDefaultPipeline

      public boolean isDefaultPipeline()
      Returns:
      boolean
    • isForceCloseOnOpen

      public boolean isForceCloseOnOpen()
      Returns:
      boolean
    • setForceCloseOnOpen

      public void setForceCloseOnOpen(boolean s)
      Parameters:
      s -
    • isDyanmicAllocated

      public boolean isDyanmicAllocated()
      Returns:
      boolean
    • setControls

      private Map<String,Control> setControls(Line line, Map<String,Control> table)
      Parameters:
      line -
      table -
      Returns:
      e
    • open

      public void open(File url)
      Note: This method does not check the exact validity of a file.

      Opens the line for reading and playback.

      This method will try its best to handle missing media length by manually reading per frame-which may take time.

      Specified by:
      open in interface Audio
      Parameters:
      url - Open a resource from a file
    • getMicrosecondLength

      public long getMicrosecondLength()
      Returns:
      long Returns the length of the media file in MicroSeconds
    • getLength

      public long getLength()
      Returns:
      long Returns the length of the media file in MilliSeconds
    • isPlaying

      public boolean isPlaying()
      Returns:
      boolean (true || false) if the stream is detected to be playing
    • getAudioFormatAbsolute

      public AudioFormat getAudioFormatAbsolute()
      Returns:
      AudioFormat Get the absolute audio format obj representing the current stream
    • isPaused

      public boolean isPaused()
      Returns:
      boolean
    • isOpen

      public boolean isOpen()
      Returns:
      boolean
    • getFrameLength

      public long getFrameLength()
      Returns:
      long
    • getFileFormat

      public FileFormat getFileFormat()
      Returns:
      FileFormat
    • getMicrosecondPosition

      public long getMicrosecondPosition()
      Defaults to the SourceDataLine's microsecond position.

      NOTE: This method does not take into account any time seeking etc and only takes into account the time since the line was opened.

      Returns:
      The microsecond position.
    • getPosition

      public long getPosition()
      Does not use the internal SourceDataLine's microsecond positioning.

      NOTE: This method does not gurantee absolute precision; however, it does take into account any time modifications including seeking.

      Returns:
      long The millisecond position
    • setPosition

      public void setPosition(long millis)
      Specified by:
      setPosition in interface Audio
      Parameters:
      millis -
    • getLongFramePosition

      public long getLongFramePosition()
      Uses the line's frame position to determine where the current pointer is.
      Returns:
      long Frame Position from the DataLine
    • addGenericUpdateListener

      public boolean addGenericUpdateListener(TailwindListener.GenericUpdateListener e)
      Parameters:
      e -
      Returns:
      boolean
    • addStatusUpdateListener

      public boolean addStatusUpdateListener(TailwindListener.StatusUpdateListener e)
      Parameters:
      e -
      Returns:
      boolean
    • addTimeListener

      public boolean addTimeListener(TailwindListener.TimeUpdateListener e)
      Parameters:
      e -
      Returns:
      boolean
    • addLineListener

      public void addLineListener(LineListener e)
      Parameters:
      e -
    • open

      public void open(URL url)
      Description copied from interface: Audio
      Opens a URL resource linker for reading
      Specified by:
      open in interface Audio
      Parameters:
      url -
    • close

      public void close()
      Description copied from interface: Audio
      Close the stream buffer
      Specified by:
      close in interface Audio
    • fadeOut

      public void fadeOut(int time)
      Fades out the audio until the audio dies.

      NOTE: This method does not automatically take care of draining and closing the current line and stream.

      Parameters:
      time - Time in milliseconds for this action to take place in.
    • play

      public void play()
      Description copied from interface: Audio
      Start reading the loaded stream into buffers
      Specified by:
      play in interface Audio
    • resetProperties

      private void resetProperties()
    • setGain

      public void setGain(float percent)
      Description copied from interface: Audio
      Sets the gain of the stream
      Specified by:
      setGain in interface Audio
      Parameters:
      percent -
    • setBalance

      public void setBalance(float balance)
      Description copied from interface: Audio
      Sets the balance of the stream
      Specified by:
      setBalance in interface Audio
      Parameters:
      balance -
    • setPan

      public void setPan(float pan)
      Parameters:
      pan -
    • setMute

      public void setMute(boolean mute)
      Specified by:
      setMute in interface Audio
      Parameters:
      mute -
    • resume

      public void resume()
      Description copied from interface: Audio
      Resume from where the stream left off after a pause.
      Specified by:
      resume in interface Audio
    • seekTo

      public void seekTo(long millis)
      This method provides a safety check upon the given time to seek.

      This method takes the current position of the stream and adds the given millis parameter to that time and resume play from there.

      If the method is called with -2, the stream will skip to the beginning (essentially restarting the stream); while -1 as a parameter will skip to the of the stream (essentially closing the stream).

      Specified by:
      seekTo in interface Audio
      Parameters:
      millis - The milliseconds to skip
    • pause

      public void pause()
      Description copied from interface: Audio
      Pause the current stream at the current spot.
      Specified by:
      pause in interface Audio
    • stop

      public void stop()
      Description copied from interface: Audio
      Stops the stream
      Specified by:
      stop in interface Audio
    • setFramePosition

      public void setFramePosition(long frame)
      Parameters:
      frame -
    • reset

      public void reset()
    • getControls

      public Map<String,Control> getControls()
      Returns:
      e