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 aroundITunesthat implements thePlayListPlayerinterface.
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 voidaddAudioPlayerListener(AudioPlayerListener listener)voidaddPlayListPlayerInterceptor(PlayListPlayerInterceptor interceptor)Adds aPlayListPlayerInterceptor.voidaddPropertyChangeListener(PropertyChangeListener propertyChangeListener)voidaddPropertyChangeListener(String propertyName, PropertyChangeListener propertyChangeListener)voidclose()Closes the audio file and associated player resources.intcurrentIndex()Always returns-1.voidfastForward()Plays the file forward at accelerated speed.AudioDevicegetAudioDevice()Current audio device.JComponentgetComponent()Main display component for the currently active playlist.longgetDuration()Duration of the song in ms.PlayListIterator<AudioSong>getIterator()Returns the currently used iterator.LonggetPlayListId()Persistent identifier of the current playlist, if available.PlayListPlayer.RepeatModegetRepeatMode()The current repeat mode.ReplayGain.TypegetReplayGainType()Currently configured type of replay gain.PlayListPlayer.ScanModegetScanMode()The current scan mode.AudioSonggetSong()Returns the currently opened song.longgetTime()Returns the current time in ms.floatgetVolume()Returns the volume.booleanisDone()True, if the song was played to the end.booleanisMuted()Indicates whether the player is muted.booleanisPaused()Indicates whether the song is currently playing.voidnext()Move to next song.voidopen(AudioSong song)Opens a song.voidopen(PlayListIterator<AudioSong> iterator)Open the song returned by the firstListIterator.next()call.voidpause()Stops playback.voidplay()Starts playback.voidplayPause()Starts playback, if song is paused, otherwise pauses playback.voidprevious()Move to previous song.voidremoveAudioPlayerListener(AudioPlayerListener listener)voidremovePlayListPlayerInterceptor(PlayListPlayerInterceptor interceptor)Removed aPlayListPlayerInterceptor.voidremovePropertyChangeListener(PropertyChangeListener propertyChangeListener)voidremovePropertyChangeListener(String propertyName, PropertyChangeListener propertyChangeListener)voidreset()Positions the player at the beginning of the file.voidsetAudioDevice(AudioDevice audioDevice)Sets the desired audio device.voidsetMuted(boolean muted)Un/mutes this player.voidsetRepeatMode(PlayListPlayer.RepeatMode mode)Sets the current repeat mode.voidsetReplayGainType(ReplayGain.Type type)Asks the player to respect the given kind of replay gain.voidsetScanMode(PlayListPlayer.ScanMode scanMode)Sets a new scan mode.voidsetTime(long time)Sets the current time in ms.voidsetTunes(ITunes iTunes)voidsetVolume(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:AudioPlayerSets the desired audio device.- Specified by:
setAudioDevicein interfaceAudioPlayer- Parameters:
audioDevice- audio device- Throws:
IllegalArgumentException- if the device is not supported
-
getAudioDevice
public AudioDevice getAudioDevice()
Description copied from interface:AudioPlayerCurrent audio device.- Specified by:
getAudioDevicein interfaceAudioPlayer- Returns:
- currently used audio device
-
next
public void next()
Description copied from interface:PlayListPlayerMove to next song. If playback was active, keep on playing.- Specified by:
nextin interfacePlayListPlayer
-
previous
public void previous()
Description copied from interface:PlayListPlayerMove to previous song. If playback was active, keep on playing.- Specified by:
previousin interfacePlayListPlayer
-
open
public void open(PlayListIterator<AudioSong> iterator) throws IOException
Description copied from interface:PlayListPlayerOpen the song returned by the firstListIterator.next()call. If playback was active, keep on playing.- Specified by:
openin 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:PlayListPlayerReturns the currently used iterator.- Specified by:
getIteratorin interfacePlayListPlayer- Returns:
- iterator
-
getPlayListId
public Long getPlayListId()
Description copied from interface:PlayListPlayerPersistent identifier of the current playlist, if available.- Specified by:
getPlayListIdin interfacePlayListPlayer- Returns:
- id or null, if not available.
-
getComponent
public JComponent getComponent()
Description copied from interface:PlayListPlayerMain display component for the currently active playlist.- Specified by:
getComponentin interfacePlayListPlayer- Returns:
- main display component for the currently active playlist
-
currentIndex
public int currentIndex()
Always returns-1.- Specified by:
currentIndexin interfacePlayListPlayer- Returns:
- -1
-
getSong
public AudioSong getSong()
Description copied from interface:AudioPlayerReturns the currently opened song.- Specified by:
getSongin interfaceAudioPlayer- Returns:
- currently opened song
-
open
public void open(AudioSong song) throws IOException
Description copied from interface:AudioPlayerOpens a song.
Calling this method withnullas argument has the same effect as callingAudioPlayer.close().- Specified by:
openin interfaceAudioPlayer- Parameters:
song- song- Throws:
IOException- if the song cannot be opened
-
play
public void play()
Description copied from interface:AudioPlayerStarts playback.- Specified by:
playin interfaceAudioPlayer
-
pause
public void pause()
Description copied from interface:AudioPlayerStops playback.- Specified by:
pausein interfaceAudioPlayer
-
playPause
public void playPause()
Description copied from interface:AudioPlayerStarts playback, if song is paused, otherwise pauses playback.- Specified by:
playPausein interfaceAudioPlayer
-
fastForward
public void fastForward()
Description copied from interface:AudioPlayerPlays the file forward at accelerated speed.- Specified by:
fastForwardin interfaceAudioPlayer
-
close
public void close()
Description copied from interface:AudioPlayerCloses the audio file and associated player resources.- Specified by:
closein interfaceAudioPlayer
-
reset
public void reset()
Description copied from interface:AudioPlayerPositions the player at the beginning of the file. Equivalent to callingAudioPlayer.setTime(long)with 0 as argument.- Specified by:
resetin interfaceAudioPlayer- See Also:
AudioPlayer.setTime(long)
-
getTime
public long getTime()
Description copied from interface:AudioPlayerReturns the current time in ms.- Specified by:
getTimein interfaceAudioPlayer- Returns:
- current time in ms
-
setTime
public void setTime(long time) throws IllegalArgumentExceptionDescription copied from interface:AudioPlayerSets the current time in ms.- Specified by:
setTimein 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:AudioPlayerDuration of the song in ms.- Specified by:
getDurationin interfaceAudioPlayer- Returns:
- the overall duration of the song in ms.
-
isDone
public boolean isDone()
Description copied from interface:AudioPlayerTrue, if the song was played to the end.- Specified by:
isDonein interfaceAudioPlayer- Returns:
- true if the song was played to the end.
-
isPaused
public boolean isPaused()
Description copied from interface:AudioPlayerIndicates whether the song is currently playing.- Specified by:
isPausedin interfaceAudioPlayer- Returns:
- false if the song is playing
-
getVolume
public float getVolume()
Description copied from interface:AudioPlayerReturns the volume.- Specified by:
getVolumein interfaceAudioPlayer- Returns:
- value between -1 and 1, negative values equating to silence
-
setVolume
public void setVolume(float volume) throws IllegalArgumentExceptionDescription copied from interface:AudioPlayerChanges the volume.- Specified by:
setVolumein 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:AudioPlayerUn/mutes this player.- Specified by:
setMutedin interfaceAudioPlayer- Parameters:
muted- muted
-
isMuted
public boolean isMuted()
Description copied from interface:AudioPlayerIndicates whether the player is muted.- Specified by:
isMutedin interfaceAudioPlayer- Returns:
- true to false
-
setReplayGainType
public void setReplayGainType(ReplayGain.Type type)
Description copied from interface:AudioPlayerAsks the player to respect the given kind of replay gain. Some players may ignore this property.- Specified by:
setReplayGainTypein interfaceAudioPlayer- Parameters:
type- type
-
getReplayGainType
public ReplayGain.Type getReplayGainType()
Description copied from interface:AudioPlayerCurrently configured type of replay gain.- Specified by:
getReplayGainTypein interfaceAudioPlayer- Returns:
- replay gain type
-
setRepeatMode
public void setRepeatMode(PlayListPlayer.RepeatMode mode)
Description copied from interface:PlayListPlayerSets the current repeat mode.- Specified by:
setRepeatModein interfacePlayListPlayer- Parameters:
mode- mode
-
getRepeatMode
public PlayListPlayer.RepeatMode getRepeatMode()
Description copied from interface:PlayListPlayerThe current repeat mode.- Specified by:
getRepeatModein interfacePlayListPlayer- Returns:
- current repeat mode
-
setScanMode
public void setScanMode(PlayListPlayer.ScanMode scanMode)
Description copied from interface:PlayListPlayerSets a new scan mode.- Specified by:
setScanModein interfacePlayListPlayer- Parameters:
scanMode- scan mode
-
getScanMode
public PlayListPlayer.ScanMode getScanMode()
Description copied from interface:PlayListPlayerThe current scan mode.- Specified by:
getScanModein interfacePlayListPlayer- Returns:
- current scan mode
-
addPlayListPlayerInterceptor
public void addPlayListPlayerInterceptor(PlayListPlayerInterceptor interceptor)
Description copied from interface:PlayListPlayerAdds aPlayListPlayerInterceptor.- Specified by:
addPlayListPlayerInterceptorin interfacePlayListPlayer- Parameters:
interceptor- interceptor
-
removePlayListPlayerInterceptor
public void removePlayListPlayerInterceptor(PlayListPlayerInterceptor interceptor)
Description copied from interface:PlayListPlayerRemoved aPlayListPlayerInterceptor.- Specified by:
removePlayListPlayerInterceptorin interfacePlayListPlayer- Parameters:
interceptor- interceptor
-
addPropertyChangeListener
public void addPropertyChangeListener(String propertyName, PropertyChangeListener propertyChangeListener)
- Specified by:
addPropertyChangeListenerin interfaceAudioPlayer
-
removePropertyChangeListener
public void removePropertyChangeListener(PropertyChangeListener propertyChangeListener)
- Specified by:
removePropertyChangeListenerin interfaceAudioPlayer
-
addPropertyChangeListener
public void addPropertyChangeListener(PropertyChangeListener propertyChangeListener)
- Specified by:
addPropertyChangeListenerin interfaceAudioPlayer
-
removePropertyChangeListener
public void removePropertyChangeListener(String propertyName, PropertyChangeListener propertyChangeListener)
- Specified by:
removePropertyChangeListenerin interfaceAudioPlayer
-
addAudioPlayerListener
public void addAudioPlayerListener(AudioPlayerListener listener)
- Specified by:
addAudioPlayerListenerin interfaceAudioPlayer
-
removeAudioPlayerListener
public void removeAudioPlayerListener(AudioPlayerListener listener)
- Specified by:
removeAudioPlayerListenerin interfaceAudioPlayer
-
-