Package com.tagtraum.audiokern.player
Class CompositePlayer
- java.lang.Object
-
- com.tagtraum.audiokern.player.CompositePlayer
-
- All Implemented Interfaces:
AudioPlayer
public class CompositePlayer extends Object implements AudioPlayer
Composite player. Acts as a facade for differentAudioPlayer
implementations that may have different capabilities.- Author:
- Hendrik Schreiber
-
-
Constructor Summary
Constructors Constructor Description CompositePlayer(AudioPlayer... audioPlayers)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addAudioPlayerListener(AudioPlayerListener listener)
void
addPropertyChangeListener(PropertyChangeListener propertyChangeListener)
void
addPropertyChangeListener(String propertyName, PropertyChangeListener propertyChangeListener)
void
close()
Closes the audio file and associated player resources.void
fastForward()
Plays the file forward at accelerated speed.AudioDevice
getAudioDevice()
Current audio device.long
getDuration()
Duration of the song in ms.ReplayGain.Type
getReplayGainType()
Currently configured type of replay gain.AudioSong
getSong()
Returns the currently opened song.long
getTime()
Returns the current time in ms.float
getVolume()
Returns the volume.boolean
isDone()
True, if the song was played to the end.boolean
isMuted()
Indicates whether the player is muted.boolean
isPaused()
Indicates whether the song is currently playing.void
open(AudioSong song)
Opens a song.void
pause()
Stops playback.void
play()
Starts playback.void
playPause()
Starts playback, if song is paused, otherwise pauses playback.void
removeAudioPlayerListener(AudioPlayerListener listener)
void
removePropertyChangeListener(PropertyChangeListener propertyChangeListener)
void
removePropertyChangeListener(String propertyName, PropertyChangeListener propertyChangeListener)
void
reset()
Positions the player at the beginning of the file.void
setAudioDevice(AudioDevice audioDevice)
Sets the desired audio device.void
setMuted(boolean muted)
Un/mutes this player.void
setReplayGainType(ReplayGain.Type type)
Asks the player to respect the given kind of replay gain.void
setTime(long time)
Sets the current time in ms.void
setVolume(float volume)
Changes the volume.String
toString()
-
-
-
Constructor Detail
-
CompositePlayer
public CompositePlayer(AudioPlayer... audioPlayers)
-
-
Method Detail
-
setAudioDevice
public void setAudioDevice(AudioDevice audioDevice) throws IllegalArgumentException
Description copied from interface:AudioPlayer
Sets the desired audio device.- Specified by:
setAudioDevice
in interfaceAudioPlayer
- Parameters:
audioDevice
- audio device- Throws:
IllegalArgumentException
- if the device is not supported
-
getAudioDevice
public AudioDevice getAudioDevice()
Description copied from interface:AudioPlayer
Current audio device.- Specified by:
getAudioDevice
in interfaceAudioPlayer
- Returns:
- currently used audio device
-
open
public void open(AudioSong song) throws IOException
Description copied from interface:AudioPlayer
Opens a song.
Calling this method withnull
as argument has the same effect as callingAudioPlayer.close()
.- Specified by:
open
in interfaceAudioPlayer
- Parameters:
song
- song- Throws:
IOException
- if the song cannot be opened
-
play
public void play()
Description copied from interface:AudioPlayer
Starts playback.- Specified by:
play
in interfaceAudioPlayer
-
pause
public void pause()
Description copied from interface:AudioPlayer
Stops playback.- Specified by:
pause
in interfaceAudioPlayer
-
playPause
public void playPause()
Description copied from interface:AudioPlayer
Starts playback, if song is paused, otherwise pauses playback.- Specified by:
playPause
in interfaceAudioPlayer
-
fastForward
public void fastForward()
Description copied from interface:AudioPlayer
Plays the file forward at accelerated speed.- Specified by:
fastForward
in interfaceAudioPlayer
-
close
public void close()
Description copied from interface:AudioPlayer
Closes the audio file and associated player resources.- Specified by:
close
in interfaceAudioPlayer
-
reset
public void reset()
Description copied from interface:AudioPlayer
Positions the player at the beginning of the file. Equivalent to callingAudioPlayer.setTime(long)
with 0 as argument.- Specified by:
reset
in interfaceAudioPlayer
- See Also:
AudioPlayer.setTime(long)
-
getSong
public AudioSong getSong()
Description copied from interface:AudioPlayer
Returns the currently opened song.- Specified by:
getSong
in interfaceAudioPlayer
- Returns:
- currently opened song
-
getTime
public long getTime()
Description copied from interface:AudioPlayer
Returns the current time in ms.- Specified by:
getTime
in interfaceAudioPlayer
- Returns:
- current time in ms
-
setTime
public void setTime(long time)
Description copied from interface:AudioPlayer
Sets the current time in ms.- Specified by:
setTime
in interfaceAudioPlayer
- Parameters:
time
- time in ms- See Also:
AudioPlayer.reset()
,AudioPlayer.getDuration()
-
getDuration
public long getDuration()
Description copied from interface:AudioPlayer
Duration of the song in ms.- Specified by:
getDuration
in interfaceAudioPlayer
- Returns:
- the overall duration of the song in ms.
-
isDone
public boolean isDone()
Description copied from interface:AudioPlayer
True, if the song was played to the end.- Specified by:
isDone
in interfaceAudioPlayer
- Returns:
- true if the song was played to the end.
-
isPaused
public boolean isPaused()
Description copied from interface:AudioPlayer
Indicates whether the song is currently playing.- Specified by:
isPaused
in interfaceAudioPlayer
- Returns:
- false if the song is playing
-
getVolume
public float getVolume()
Description copied from interface:AudioPlayer
Returns the volume.- Specified by:
getVolume
in interfaceAudioPlayer
- Returns:
- value between -1 and 1, negative values equating to silence
-
setVolume
public void setVolume(float volume)
Description copied from interface:AudioPlayer
Changes the volume.- Specified by:
setVolume
in interfaceAudioPlayer
- Parameters:
volume
- value between -1 and 1, negative values equating to silence. A volume value outside the valid range will lead to an IllegalArgumentException
-
setMuted
public void setMuted(boolean muted)
Description copied from interface:AudioPlayer
Un/mutes this player.- Specified by:
setMuted
in interfaceAudioPlayer
- Parameters:
muted
- muted
-
isMuted
public boolean isMuted()
Description copied from interface:AudioPlayer
Indicates whether the player is muted.- Specified by:
isMuted
in interfaceAudioPlayer
- Returns:
- true to false
-
setReplayGainType
public void setReplayGainType(ReplayGain.Type type)
Description copied from interface:AudioPlayer
Asks the player to respect the given kind of replay gain. Some players may ignore this property.- Specified by:
setReplayGainType
in interfaceAudioPlayer
- Parameters:
type
- type
-
getReplayGainType
public ReplayGain.Type getReplayGainType()
Description copied from interface:AudioPlayer
Currently configured type of replay gain.- Specified by:
getReplayGainType
in interfaceAudioPlayer
- Returns:
- replay gain type
-
addPropertyChangeListener
public void addPropertyChangeListener(PropertyChangeListener propertyChangeListener)
- Specified by:
addPropertyChangeListener
in interfaceAudioPlayer
-
addPropertyChangeListener
public void addPropertyChangeListener(String propertyName, PropertyChangeListener propertyChangeListener)
- Specified by:
addPropertyChangeListener
in interfaceAudioPlayer
-
removePropertyChangeListener
public void removePropertyChangeListener(PropertyChangeListener propertyChangeListener)
- Specified by:
removePropertyChangeListener
in interfaceAudioPlayer
-
removePropertyChangeListener
public void removePropertyChangeListener(String propertyName, PropertyChangeListener propertyChangeListener)
- Specified by:
removePropertyChangeListener
in interfaceAudioPlayer
-
addAudioPlayerListener
public void addAudioPlayerListener(AudioPlayerListener listener)
- Specified by:
addAudioPlayerListener
in interfaceAudioPlayer
-
removeAudioPlayerListener
public void removeAudioPlayerListener(AudioPlayerListener listener)
- Specified by:
removeAudioPlayerListener
in interfaceAudioPlayer
-
-