Package com.tagtraum.tunes
Class Player
- java.lang.Object
-
- com.tagtraum.tunes.Player
-
- All Implemented Interfaces:
AudioPlayer
,PlayListPlayer
public class Player extends Object implements PlayListPlayer
Wrapper aroundITunes
that implements thePlayListPlayer
interface.
Note that this implementation cannot return meaningfulcurrentIndex()
values, as the sorting in iTunes may differ from the sorting in our player interface.- Author:
- Hendrik Schreiber
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.tagtraum.audiokern.PlayListPlayer
PlayListPlayer.RepeatMode, PlayListPlayer.ScanMode
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addAudioPlayerListener(AudioPlayerListener listener)
void
addPlayListPlayerInterceptor(PlayListPlayerInterceptor interceptor)
Adds aPlayListPlayerInterceptor
.void
addPropertyChangeListener(PropertyChangeListener propertyChangeListener)
void
addPropertyChangeListener(String propertyName, PropertyChangeListener propertyChangeListener)
void
close()
Closes the audio file and associated player resources.int
currentIndex()
Always returns-1
.void
fastForward()
Plays the file forward at accelerated speed.AudioDevice
getAudioDevice()
Current audio device.JComponent
getComponent()
Main display component for the currently active playlist.long
getDuration()
Duration of the song in ms.PlayListIterator<AudioSong>
getIterator()
Returns the currently used iterator.Long
getPlayListId()
Persistent identifier of the current playlist, if available.PlayListPlayer.RepeatMode
getRepeatMode()
The current repeat mode.ReplayGain.Type
getReplayGainType()
Currently configured type of replay gain.PlayListPlayer.ScanMode
getScanMode()
The current scan mode.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
next()
Move to next song.void
open(AudioSong song)
Opens a song.void
open(PlayListIterator<AudioSong> iterator)
Open the song returned by the firstListIterator.next()
call.void
pause()
Stops playback.void
play()
Starts playback.void
playPause()
Starts playback, if song is paused, otherwise pauses playback.void
previous()
Move to previous song.void
removeAudioPlayerListener(AudioPlayerListener listener)
void
removePlayListPlayerInterceptor(PlayListPlayerInterceptor interceptor)
Removed aPlayListPlayerInterceptor
.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
setRepeatMode(PlayListPlayer.RepeatMode mode)
Sets the current repeat mode.void
setReplayGainType(ReplayGain.Type type)
Asks the player to respect the given kind of replay gain.void
setScanMode(PlayListPlayer.ScanMode scanMode)
Sets a new scan mode.void
setTime(long time)
Sets the current time in ms.void
setTunes(ITunes iTunes)
void
setVolume(float volume)
Changes the volume.
-
-
-
Constructor Detail
-
Player
public Player(ITunes iTunes)
-
Player
public Player()
-
-
Method Detail
-
setTunes
public void setTunes(ITunes iTunes)
- Parameters:
iTunes
- a new iTunes object or null, to remove listeners and stop the update timer.
-
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
-
next
public void next()
Description copied from interface:PlayListPlayer
Move to next song. If playback was active, keep on playing.- Specified by:
next
in interfacePlayListPlayer
-
previous
public void previous()
Description copied from interface:PlayListPlayer
Move to previous song. If playback was active, keep on playing.- Specified by:
previous
in interfacePlayListPlayer
-
open
public void open(PlayListIterator<AudioSong> iterator) throws IOException
Description copied from interface:PlayListPlayer
Open the song returned by the firstListIterator.next()
call. If playback was active, keep on playing.- Specified by:
open
in interfacePlayListPlayer
- Throws:
IOException
- if the first song (obtained throughListIterator.next()
) cannot be opened- See Also:
AudioPlayer.open(AudioSong)
-
getIterator
public PlayListIterator<AudioSong> getIterator()
Description copied from interface:PlayListPlayer
Returns the currently used iterator.- Specified by:
getIterator
in interfacePlayListPlayer
- Returns:
- iterator
-
getPlayListId
public Long getPlayListId()
Description copied from interface:PlayListPlayer
Persistent identifier of the current playlist, if available.- Specified by:
getPlayListId
in interfacePlayListPlayer
- Returns:
- id or null, if not available.
-
getComponent
public JComponent getComponent()
Description copied from interface:PlayListPlayer
Main display component for the currently active playlist.- Specified by:
getComponent
in interfacePlayListPlayer
- Returns:
- main display component for the currently active playlist
-
currentIndex
public int currentIndex()
Always returns-1
.- Specified by:
currentIndex
in interfacePlayListPlayer
- Returns:
- -1
-
getSong
public AudioSong getSong()
Description copied from interface:AudioPlayer
Returns the currently opened song.- Specified by:
getSong
in interfaceAudioPlayer
- Returns:
- currently opened song
-
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)
-
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) throws IllegalArgumentException
Description copied from interface:AudioPlayer
Sets the current time in ms.- Specified by:
setTime
in interfaceAudioPlayer
- Parameters:
time
- time in ms- Throws:
IllegalArgumentException
- if the time is not valid because it is either less than 0 or greater than duration- 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) throws IllegalArgumentException
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- Throws:
IllegalArgumentException
- if the value is outside the valid range
-
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
-
setRepeatMode
public void setRepeatMode(PlayListPlayer.RepeatMode mode)
Description copied from interface:PlayListPlayer
Sets the current repeat mode.- Specified by:
setRepeatMode
in interfacePlayListPlayer
- Parameters:
mode
- mode
-
getRepeatMode
public PlayListPlayer.RepeatMode getRepeatMode()
Description copied from interface:PlayListPlayer
The current repeat mode.- Specified by:
getRepeatMode
in interfacePlayListPlayer
- Returns:
- current repeat mode
-
setScanMode
public void setScanMode(PlayListPlayer.ScanMode scanMode)
Description copied from interface:PlayListPlayer
Sets a new scan mode.- Specified by:
setScanMode
in interfacePlayListPlayer
- Parameters:
scanMode
- scan mode
-
getScanMode
public PlayListPlayer.ScanMode getScanMode()
Description copied from interface:PlayListPlayer
The current scan mode.- Specified by:
getScanMode
in interfacePlayListPlayer
- Returns:
- current scan mode
-
addPlayListPlayerInterceptor
public void addPlayListPlayerInterceptor(PlayListPlayerInterceptor interceptor)
Description copied from interface:PlayListPlayer
Adds aPlayListPlayerInterceptor
.- Specified by:
addPlayListPlayerInterceptor
in interfacePlayListPlayer
- Parameters:
interceptor
- interceptor
-
removePlayListPlayerInterceptor
public void removePlayListPlayerInterceptor(PlayListPlayerInterceptor interceptor)
Description copied from interface:PlayListPlayer
Removed aPlayListPlayerInterceptor
.- Specified by:
removePlayListPlayerInterceptor
in interfacePlayListPlayer
- Parameters:
interceptor
- interceptor
-
addPropertyChangeListener
public void addPropertyChangeListener(String propertyName, PropertyChangeListener propertyChangeListener)
- Specified by:
addPropertyChangeListener
in interfaceAudioPlayer
-
removePropertyChangeListener
public void removePropertyChangeListener(PropertyChangeListener propertyChangeListener)
- Specified by:
removePropertyChangeListener
in interfaceAudioPlayer
-
addPropertyChangeListener
public void addPropertyChangeListener(PropertyChangeListener propertyChangeListener)
- Specified by:
addPropertyChangeListener
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
-
-