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 TypeClassDescriptionclass
A Pipeline strategy that intends to use the Java Sound API to play audio.class
This is the secondary pipeline that is supplied when dealing with -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate AudioInputStream
static final String
private final TailwindEventManager
private boolean
private FileFormat
private AudioFormat
private long
private SourceDataLine
static final int
static final String
private long
private long
private int
private boolean
static final String
private boolean
private TailwindPipelineMethod
private boolean
private final Object
private File
private final Object
private ExecutorService
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
void
boolean
boolean
void
close()
Close the stream buffervoid
fadeOut
(int time) Fades out the audio until the audio dies.long
long
long
Uses the line's frame position to determine where the current pointer is.long
long
Defaults to the SourceDataLine's microsecond position.long
Does not use the internal SourceDataLine's microsecond positioning.private void
boolean
boolean
boolean
boolean
isOpen()
boolean
isPaused()
boolean
void
Note: This method does not check the exact validity of a file.void
Opens a URL resource linker for readingvoid
pause()
Pause the current stream at the current spot.void
play()
Start reading the loaded stream into buffersvoid
reset()
private void
void
resume()
Resume from where the stream left off after a pause.void
seekTo
(long millis) This method provides a safety check upon the given time to seek.void
setBalance
(float balance) Sets the balance of the streamsetControls
(Line line, Map<String, Control> table) void
setDynamicAllocation
(boolean s) void
setForceCloseOnOpen
(boolean s) void
setFramePosition
(long frame) void
setGain
(float percent) Sets the gain of the streamvoid
setMute
(boolean mute) void
setPan
(float pan) void
setPipelineMethod
(TailwindPipelineMethod pipeline) void
setPosition
(long millis) void
stop()
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:
setPosition
in 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:Audio
Opens a URL resource linker for reading -
close
public void close()Description copied from interface:Audio
Close 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:Audio
Start reading the loaded stream into buffers -
resetProperties
private void resetProperties() -
setGain
public void setGain(float percent) Description copied from interface:Audio
Sets the gain of the stream -
setBalance
public void setBalance(float balance) Description copied from interface:Audio
Sets the balance of the stream- Specified by:
setBalance
in 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:Audio
Resume 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:Audio
Pause the current stream at the current spot. -
stop
public void stop()Description copied from interface:Audio
Stops the stream -
setFramePosition
public void setFramePosition(long frame) - Parameters:
frame
-
-
reset
public void reset() -
getControls
- Returns:
- e
-