Class Tailwind
- All Implemented Interfaces:
Audio
- Direct Known Subclasses:
TailwindPlaylist
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassA Pipeline strategy that intends to use the Java Sound API to play audio.classThis is the secondary pipeline that is supplied when dealing with -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate AudioInputStreamstatic final Stringprivate final TailwindEventManagerprivate booleanprivate FileFormatprivate AudioFormatprivate longprivate SourceDataLinestatic final intstatic final Stringprivate longprivate longprivate intprivate booleanstatic final Stringprivate booleanprivate TailwindPipelineMethodprivate booleanprivate final Objectprivate Fileprivate final Objectprivate ExecutorService -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanvoidbooleanbooleanvoidclose()Close the stream buffervoidfadeOut(int time) Fades out the audio until the audio dies.longlonglongUses the line's frame position to determine where the current pointer is.longlongDefaults to the SourceDataLine's microsecond position.longDoes not use the internal SourceDataLine's microsecond positioning.private voidbooleanbooleanbooleanbooleanisOpen()booleanisPaused()booleanvoidNote: This method does not check the exact validity of a file.voidOpens a URL resource linker for readingvoidpause()Pause the current stream at the current spot.voidplay()Start reading the loaded stream into buffersvoidreset()private voidvoidresume()Resume from where the stream left off after a pause.voidseekTo(long millis) This method provides a safety check upon the given time to seek.voidsetBalance(float balance) Sets the balance of the streamsetControls(Line line, Map<String, Control> table) voidsetDynamicAllocation(boolean s) voidsetForceCloseOnOpen(boolean s) voidsetFramePosition(long frame) voidsetGain(float percent) Sets the gain of the streamvoidsetMute(boolean mute) voidsetPan(float pan) voidsetPipelineMethod(TailwindPipelineMethod pipeline) voidsetPosition(long millis) voidstop()Stops the stream
-
Field Details
-
MAGIC_NUMBER
public static final int MAGIC_NUMBER- See Also:
-
MASTER_GAIN_STR
- See Also:
-
BALANCE_STR
- See Also:
-
PAN_STR
- See Also:
-
referencable
-
timeRef
-
events
-
resource
-
my_magic_number
private int my_magic_number -
line
-
pipeline
-
format
-
controlTable
-
open
private boolean open -
paused
private boolean paused -
playing
private boolean playing -
forceClose
private boolean forceClose -
ais
-
microsecondLength
private long microsecondLength -
frameLength
private long frameLength -
milliPos
private long milliPos -
worker
-
formatAudio
-
-
Constructor Details
-
Tailwind
public Tailwind()
-
-
Method Details
-
handleException
- Parameters:
e-
-
setDynamicAllocation
public void setDynamicAllocation(boolean s) - Parameters:
s-
-
getPipelineMethod
- Returns:
- TailwindPipelineMethod
-
setPipelineMethod
- 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
- Parameters:
line-table-- Returns:
- e
-
open
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.
-
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
- 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
- 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:
setPositionin interfaceAudio- 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
- Parameters:
e-- Returns:
- boolean
-
addStatusUpdateListener
- Parameters:
e-- Returns:
- boolean
-
addTimeListener
- Parameters:
e-- Returns:
- boolean
-
addLineListener
- Parameters:
e-
-
open
Description copied from interface:AudioOpens a URL resource linker for reading -
close
public void close()Description copied from interface:AudioClose the stream buffer -
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:AudioStart reading the loaded stream into buffers -
resetProperties
private void resetProperties() -
setGain
public void setGain(float percent) Description copied from interface:AudioSets the gain of the stream -
setBalance
public void setBalance(float balance) Description copied from interface:AudioSets the balance of the stream- Specified by:
setBalancein interfaceAudio- Parameters:
balance-
-
setPan
public void setPan(float pan) - Parameters:
pan-
-
setMute
public void setMute(boolean mute) -
resume
public void resume()Description copied from interface:AudioResume from where the stream left off after a pause. -
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).
-
pause
public void pause()Description copied from interface:AudioPause the current stream at the current spot. -
stop
public void stop()Description copied from interface:AudioStops the stream -
setFramePosition
public void setFramePosition(long frame) - Parameters:
frame-
-
reset
public void reset() -
getControls
- Returns:
- e
-