Package com.tagtraum.audiokern.player
Class AVPlayer
- java.lang.Object
-
- com.tagtraum.audiokern.player.AVPlayer
-
- All Implemented Interfaces:
AudioPlayer
public class AVPlayer extends Object implements AudioPlayer
AVFoundation-basedAudioPlayer. Available on 64-bit macOS > 10.7.- Author:
- Hendrik Schreiber
- See Also:
isSupported()
-
-
Constructor Summary
Constructors Constructor Description AVPlayer()AVPlayer(ExecutorService serializer)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddAudioPlayerListener(AudioPlayerListener listener)voidaddPropertyChangeListener(PropertyChangeListener propertyChangeListener)voidaddPropertyChangeListener(String propertyName, PropertyChangeListener propertyChangeListener)voidclose()Closes the audio file and associated player resources.voidfastForward()Plays the file forward at accelerated speed.protected voidfinalize()AudioDevicegetAudioDevice()Current audio device.longgetDuration()Duration of the song in ms.floatgetPreGain()ReplayGain.TypegetReplayGainType()Currently configured type of replay gain.AudioSonggetSong()Returns the currently opened song.com.tagtraum.audiokern.player.AVPlayer.AVPlayerStatusgetStatus()longgetTime()Returns the current time in ms.com.tagtraum.audiokern.player.AVPlayer.AVPlayerTimeControlStatusgetTimeControlStatus()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.static booleanisSupported()Indicates, whether an AVFoundation player is available.booleanisVolumeNormalizationEnabled()voidopen(AudioSong song)Opens a song.voidpause()Stops playback.voidplay()Starts playback.voidplayPause()Starts playback, if song is paused, otherwise pauses playback.voidremoveAudioPlayerListener(AudioPlayerListener listener)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.voidsetPreGain(float preGain)voidsetReplayGainType(ReplayGain.Type type)Asks the player to respect the given kind of replay gain.voidsetTime(long time)Sets the current time in ms.voidsetVolume(float volume)Changes the volume.voidsetVolumeNormalizationEnabled(boolean volumeNormalizationEnabled)StringtoString()
-
-
-
Constructor Detail
-
AVPlayer
public AVPlayer() throws UnsupportedOperationException- Throws:
UnsupportedOperationException- if the player is not supported by the native platform- See Also:
isSupported()
-
AVPlayer
public AVPlayer(ExecutorService serializer) throws UnsupportedOperationException
- Throws:
UnsupportedOperationException- if the player is not supported by the native platform- See Also:
isSupported()
-
-
Method Detail
-
isSupported
public static boolean isSupported()
Indicates, whether an AVFoundation player is available.- Returns:
- true or false
-
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
-
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
-
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)
-
fastForward
public void fastForward()
Description copied from interface:AudioPlayerPlays the file forward at accelerated speed.- Specified by:
fastForwardin interfaceAudioPlayer
-
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)
Description copied from interface:AudioPlayerSets the current time in ms.- Specified by:
setTimein interfaceAudioPlayer- Parameters:
time- time in ms- 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.
-
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)
Description 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
-
getPreGain
public float getPreGain()
-
setPreGain
public void setPreGain(float preGain)
-
isVolumeNormalizationEnabled
public boolean isVolumeNormalizationEnabled()
-
setVolumeNormalizationEnabled
public void setVolumeNormalizationEnabled(boolean volumeNormalizationEnabled)
-
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.
-
isMuted
public boolean isMuted()
Description copied from interface:AudioPlayerIndicates whether the player is muted.- Specified by:
isMutedin interfaceAudioPlayer- Returns:
- true to false
-
setMuted
public void setMuted(boolean muted)
Description copied from interface:AudioPlayerUn/mutes this player.- Specified by:
setMutedin interfaceAudioPlayer- Parameters:
muted- muted
-
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
-
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
-
playPause
public void playPause()
Description copied from interface:AudioPlayerStarts playback, if song is paused, otherwise pauses playback.- Specified by:
playPausein interfaceAudioPlayer
-
close
public void close()
Description copied from interface:AudioPlayerCloses the audio file and associated player resources.- Specified by:
closein interfaceAudioPlayer
-
addPropertyChangeListener
public void addPropertyChangeListener(PropertyChangeListener propertyChangeListener)
- Specified by:
addPropertyChangeListenerin interfaceAudioPlayer
-
removePropertyChangeListener
public void removePropertyChangeListener(PropertyChangeListener propertyChangeListener)
- Specified by:
removePropertyChangeListenerin interfaceAudioPlayer
-
addPropertyChangeListener
public void addPropertyChangeListener(String propertyName, 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
-
finalize
protected void finalize() throws Throwable
-
getStatus
public com.tagtraum.audiokern.player.AVPlayer.AVPlayerStatus getStatus()
-
getTimeControlStatus
public com.tagtraum.audiokern.player.AVPlayer.AVPlayerTimeControlStatus getTimeControlStatus()
-
-