P
- subClasspublic abstract class APlayer<P extends APlayer> extends java.lang.Object implements IPlayer<P>, IPlayerBase.Listener
Player
Modifier and Type | Class and Description |
---|---|
protected class |
APlayer.ComponentListener |
protected class |
APlayer.ComponentReceiver |
IPlayer.Listener
Modifier and Type | Field and Description |
---|---|
protected boolean |
abAutoClear |
protected boolean |
abEnabled
[A-B] whether enabled
|
protected long |
abEndPosition
[A-B] end position
|
protected int |
abInterval
[A-B] loop interval
|
protected int |
abLoopedCount
[A-B] looped count tag
|
protected int |
abLoopMode
[A-B] Loop Mode -8: infinity loop x(<=0): not loop 1++(>0): specified number
loop
|
protected long |
abStartPosition
[A-B] start position
|
protected AudioMgrHelper |
audioMgrHelper |
protected android.content.IntentFilter |
componentIntentFilter |
protected APlayer.ComponentListener |
componentListener |
protected APlayer.ComponentReceiver |
componentReceiver |
private boolean |
componentReceiverRegistered |
protected android.content.Context |
context |
private int |
currentAudioFocusState |
protected java.lang.String |
currentMediaId |
protected int |
currentPosUnitIndex
current PositionUnit index
|
protected boolean |
enabledAudioFocusManage |
protected android.os.Handler |
handler |
protected IMediaPlayer |
internalPlayer |
protected boolean |
isInAB
Whether the current position in the range of [A-B]
|
protected boolean |
isInPosUnit
Whether the current position in the range of position unit
|
protected java.util.concurrent.CopyOnWriteArrayList<IPlayer.Listener> |
listeners |
private IMediaQueue |
mediaQueue |
protected android.os.Handler |
methodAgent
Simple Method Agent What Code 1: start(); 31: seekToPositionUnitIndex(currentPosUnitIndex)
311: seekToPositionUnitIndex(currentPosUnitIndex) with posUnitLoopedCount++ 3111:
seekToPositionUnitIndex(msg.arg1) 32: seekTo(abStartPosition) 322:
seekTo(abStartPosition) with abLoopedCount++
|
protected long |
pendingSeekToMs |
protected IPositionUnitList |
posUnitList |
protected int |
posUnitLoopedCount
[position unit] looped count tag
|
protected boolean |
posUnitLoopEnabled
[position unit] Loop whether enabled
|
protected java.util.ArrayList<java.lang.Integer> |
posUnitLoopIndexList
specified [position unit] loop List(index)
|
protected int |
posUnitLoopInterval
[position unit] loop interval
|
protected int |
posUnitLoopMode
[position unit] Loop Mode -8: infinity loop x(<=0): not loop 1++(>0): specified
number loop
|
protected boolean |
shouldAutoPlayWhenPrepared |
protected boolean |
shouldAutoPlayWhenSeekComplete |
protected java.lang.String |
TAG |
private java.lang.Runnable |
updatePlayProgressAction |
private boolean |
updatePlayProgressBaseInterruptConditions |
protected long |
updatePlayProgressDelayMs |
protected android.net.wifi.WifiManager.WifiLock |
wifiLock |
STATE_BUFFERING, STATE_ENDED, STATE_GOT_SOURCE, STATE_IDLE, STATE_READY
Constructor and Description |
---|
APlayer()
Not param constructor.
|
APlayer(android.content.Context context)
Default support, base on context of function Module.
|
Modifier and Type | Method and Description |
---|---|
protected int |
abLoopProcessing(int processFrom) |
protected boolean |
abProgress(long position) |
void |
addListener(IPlayer.Listener listener) |
protected boolean |
beforeStart() |
int |
calibrateCurrentPositionUnitIndex(long position)
generally not use(player inside Will automatically maintain current [position unit] index
calibrate)
|
void |
clearAB()
Clear A-B all tag Tips: setClearAB(false) also don't manual invoke clearAB(), will save
all tag.
|
void |
clearVideo() |
protected boolean |
configureAudioFocus() |
boolean |
fastForwardRewind(long ms) |
AudioMgrHelper |
getAudioMgrHelper() |
protected android.content.IntentFilter |
getComponentIntentFilter() |
protected APlayer.ComponentListener |
getComponentListener() |
protected APlayer.ComponentReceiver |
getComponentReceiver() |
java.lang.String |
getCurrentMediaId()
Returns current media id (custom or default[string representation of this play uri])
|
long |
getCurrentPosition() |
int |
getCurrentPositionUnitIndex() |
long |
getDuration() |
IMediaQueue |
getMediaQueue()
get a media queue, if not
IPlayer.setMediaQueue(IMediaQueue) , it return default media queue |
float |
getPlaybackSpeed() |
int |
getPlaybackState() |
float |
getVolume()
Returns the volume, with 0 being silence and 1 being unity gain.
|
private void |
giveUpAudioFocus() |
protected boolean |
haveSeekToPending() |
P |
init(IMediaPlayer mediaPlayer)
Init internal media player
|
protected boolean |
initConfig(IMediaPlayer mediaPlayer) |
IMediaPlayer |
internalPlayer()
Get a internal mediaPlayer
|
boolean |
isPlayable()
Playback state !=
IPlayerBase.STATE_IDLE != IPlayerBase.STATE_GOT_SOURCE != IPlayerBase.STATE_BUFFERING |
boolean |
isPlaying() |
protected boolean |
isPrepared(android.net.Uri uri) |
protected void |
onABProgress(long position,
long duration,
int abState) |
protected boolean |
onAudioFocusChange(int focusChange) |
void |
onBufferingUpdate(int percent) |
int |
onCompletion() |
boolean |
onError(int what,
int extra,
java.lang.Exception e) |
boolean |
onInfo(int what,
int extra) |
protected boolean |
onIntent(android.content.Intent intent) |
protected void |
onNotificationRequired(int order) |
protected boolean |
onPlayProgress(long position,
long duration) |
protected void |
onPositionUnitProgress(long position,
int posUnitIndex,
int posUnitState) |
void |
onPrepared() |
void |
onSeekComplete() |
void |
onStateChanged(int playbackState)
Called when the value returned from
IPlayerBase.getPlaybackState() changes. |
void |
onVideoSizeChanged(int width,
int height,
int unappliedRotationDegrees,
float pixelWidthHeightRatio) |
boolean |
pause() |
boolean |
play() |
boolean |
play(IMediaItem mediaItem) |
boolean |
play(android.net.Uri uri) |
boolean |
playMediaId(java.lang.String mediaId) |
protected int |
positionUnitLoopProcessing(int processFrom) |
protected boolean |
positionUnitProgress(long position) |
protected boolean |
posUnitListAvailable() |
boolean |
prepare(IMediaItem mediaItem) |
protected boolean |
prepare(IMediaItem mediaItem,
boolean shouldAutoPlayWhenPrepared) |
boolean |
prepare(android.net.Uri uri) |
protected boolean |
prepare(android.net.Uri uri,
boolean shouldAutoPlayWhenPrepared) |
boolean |
prepareMediaId(java.lang.String mediaId) |
protected boolean |
prepareMediaId(java.lang.String mediaId,
boolean shouldAutoPlayWhenPrepared) |
protected void |
registerComponentReceiver() |
void |
release() |
void |
removeListener(IPlayer.Listener listener) |
void |
reset() |
protected abstract P |
returnThis()
Sub Class Override
|
boolean |
seekTo(long ms)
internal call
IPlayer.seekTo(long, int) Max processing level |
boolean |
seekTo(long ms,
int processingLevel)
Support custom processing level of seekTo
|
void |
seekToPending(long ms)
set a pending seekTo in before start() dispose
|
long |
seekToPositionUnitIndex(int posUnitIndex)
Seeks to specified PositionUnitIndex
|
long |
seekToProgress(int progress,
int progressMax)
Seeks to specified progress
|
P |
setAB(long startPos,
long endPos)
Set A-B start position and end position with reset ab all tag
|
P |
setAB(long startPos,
long endPos,
int loopMode,
int loopInterval)
Set A-B internal call
IPlayer.setAB(long, long) , IPlayer.setABLoop(int, int)
*param loopMode,loopInterval can use C.PARAM_ORIGINAL keeping the original values
*param loopMode,loopInterval can use C.PARAM_UNSET /C.PARAM_RESET
unset/reset values |
P |
setABLoop(int loopMode,
int loopInterval)
Set A-B loop *param loopMode,loopInterval can use
C.PARAM_ORIGINAL keeping the
original values *param loopMode,loopInterval can use C.PARAM_UNSET /C.PARAM_RESET unset/reset values |
P |
setClearAB(boolean autoClear)
Set auto clear A-B all tag(when A-B finish) WARNING: If for special reasons cause A-B is
not finish, will don't auto clear.
|
void |
setCurrentPositionUnitIndex(int posUnitIndex)
generally not use(player inside Will automatically maintain current [position unit] index)
|
P |
setEnabledAudioFocusManage(boolean enabled) |
P |
setEnabledPositionUnitLoop(boolean enabled,
int loopMode,
int loopInterval)
Set the enabled,loopMode,loopInterval of this position unit loop, with reset position unit
looped count tag *param loopMode,loopInterval can use
C.PARAM_ORIGINAL keeping
the original values *param loopMode,loopInterval can use C.PARAM_UNSET /C.PARAM_RESET unset/reset values |
P |
setEnabledWifiLock(boolean enabled)
Set enabled wifi lock, to hold a Wifi lock, which prevents the player from going to sleep while
the media is playing.
|
void |
setMediaQueue(IMediaQueue mediaQueue)
set a new media queue for player
|
boolean |
setPlaybackSpeed(float speed) |
P |
setPositionUnitList(IPositionUnitList posUnitList)
WARNING: must ensure
IPositionUnitList.getMediaId() equals IPlayer.getCurrentMediaId()
can work normally |
protected void |
setPositionUnitLoop(int loopMode,
int loopInterval) |
P |
setPositionUnitLoopIndexList(java.util.ArrayList<java.lang.Integer> posUnitLoopIndexList)
WARNING: media source change with specify to loop of [position unit] index list will be reset
|
P |
setUpdatePlayProgressDelayMs(long updatePlayProgressDelayMs)
Sets the updatePlayProgress delay.
|
void |
setVideo(android.view.SurfaceView surfaceView) |
void |
setVideo(android.view.TextureView textureView) |
void |
setVolume(float volume)
Sets the volume, with 0 being silence and 1 being unity gain.
|
P |
shouldAutoPlayWhenSeekComplete(boolean shouldAutoPlayWhenSeekComplete)
Generally used in front of the seekTo...(.) to ensure that seek complete to auto play
immediately after
|
void |
shutdown()
Shut down player (release all resources)
|
boolean |
start() |
void |
stop() |
void |
supportBaseOnContextOfFunctionModule(android.content.Context context)
Support, base on context of function Module.
|
private void |
tryToGetAudioFocus() |
protected void |
unregisterComponentReceiver() |
protected void |
updatePlayProgress(int updatePlayProgressCommand) |
protected boolean |
updatePlayProgressInterruptConditions() |
protected IMediaPlayer internalPlayer
protected long pendingSeekToMs
protected final java.util.concurrent.CopyOnWriteArrayList<IPlayer.Listener> listeners
protected boolean shouldAutoPlayWhenPrepared
protected boolean shouldAutoPlayWhenSeekComplete
private final java.lang.Runnable updatePlayProgressAction
protected long updatePlayProgressDelayMs
private boolean updatePlayProgressBaseInterruptConditions
protected int currentPosUnitIndex
protected IPositionUnitList posUnitList
protected boolean isInPosUnit
...[start~PosUnit~end]...
protected boolean posUnitLoopEnabled
protected int posUnitLoopMode
protected int posUnitLoopInterval
protected int posUnitLoopedCount
protected java.util.ArrayList<java.lang.Integer> posUnitLoopIndexList
protected final android.os.Handler handler
protected final android.os.Handler methodAgent
protected boolean abEnabled
protected long abStartPosition
protected long abEndPosition
protected int abLoopMode
protected int abInterval
protected int abLoopedCount
protected boolean abAutoClear
protected boolean isInAB
...[start~AB~end]...
private IMediaQueue mediaQueue
protected java.lang.String currentMediaId
protected android.net.wifi.WifiManager.WifiLock wifiLock
protected AudioMgrHelper audioMgrHelper
private int currentAudioFocusState
protected boolean enabledAudioFocusManage
protected APlayer.ComponentListener componentListener
private boolean componentReceiverRegistered
protected android.content.IntentFilter componentIntentFilter
protected APlayer.ComponentReceiver componentReceiver
protected java.lang.String TAG
protected android.content.Context context
public APlayer()
public APlayer(@NonNull android.content.Context context)
protected abstract P returnThis()
public class Player extends APlayer<Player> { @Override protected Player returnThis() { return this; } }
public IMediaPlayer internalPlayer()
IPlayer
Player run core by internal maintaining mediaPlayer. In general is not recommended unless you want to operate some special functions. * note that internalPlayer and Player * at the same time operating possible when the incompatibilities
internalPlayer
in interface IPlayer<P extends APlayer>
protected boolean initConfig(IMediaPlayer mediaPlayer)
public P init(IMediaPlayer mediaPlayer)
IPlayer
protected boolean isPrepared(android.net.Uri uri)
protected boolean prepare(android.net.Uri uri, boolean shouldAutoPlayWhenPrepared)
protected boolean prepare(IMediaItem mediaItem, boolean shouldAutoPlayWhenPrepared)
protected boolean prepareMediaId(java.lang.String mediaId, boolean shouldAutoPlayWhenPrepared)
public boolean prepare(android.net.Uri uri)
public boolean prepare(IMediaItem mediaItem)
public boolean prepareMediaId(java.lang.String mediaId)
prepareMediaId
in interface IPlayer<P extends APlayer>
public boolean play(android.net.Uri uri)
public boolean play(IMediaItem mediaItem)
public boolean playMediaId(java.lang.String mediaId)
playMediaId
in interface IPlayer<P extends APlayer>
public void shutdown()
IPlayer
public void seekToPending(long ms)
IPlayer
seekToPending
in interface IPlayer<P extends APlayer>
protected boolean haveSeekToPending()
public long seekToProgress(int progress, int progressMax)
IPlayer
seekToProgress
in interface IPlayer<P extends APlayer>
progress
- current progressprogressMax
- the upper limit of this progress range.public boolean start()
start
in interface IPlayerBase
protected boolean beforeStart()
public boolean pause()
pause
in interface IPlayerBase
public boolean seekTo(long ms, int processingLevel)
IPlayer
public boolean seekTo(long ms)
IPlayer
IPlayer.seekTo(long, int)
Max processing levelpublic boolean fastForwardRewind(long ms)
fastForwardRewind
in interface IPlayer<P extends APlayer>
ms
- fastForwardMs/RewindMs public void stop()
stop
in interface IPlayerBase
public void reset()
reset
in interface IPlayerBase
public void release()
release
in interface IPlayerBase
public void setVideo(android.view.SurfaceView surfaceView)
setVideo
in interface IPlayerBase
public void setVideo(android.view.TextureView textureView)
setVideo
in interface IPlayerBase
public void clearVideo()
clearVideo
in interface IPlayerBase
public void setVolume(float volume)
IPlayerBase
setVolume
in interface IPlayerBase
public float getVolume()
IPlayerBase
getVolume
in interface IPlayerBase
public long getCurrentPosition()
getCurrentPosition
in interface IPlayerBase
public long getDuration()
getDuration
in interface IPlayerBase
public boolean isPlaying()
isPlaying
in interface IPlayerBase
public boolean setPlaybackSpeed(float speed)
setPlaybackSpeed
in interface IPlayerBase
public float getPlaybackSpeed()
getPlaybackSpeed
in interface IPlayerBase
public int getPlaybackState()
getPlaybackState
in interface IPlayerBase
STATE
constants defined public boolean isPlayable()
IPlayerBase
isPlayable
in interface IPlayerBase
public void addListener(IPlayer.Listener listener)
addListener
in interface IPlayer<P extends APlayer>
listener
- IPlayer.Listener
PlayerListener
( ) IPlayer.Listener
public void removeListener(IPlayer.Listener listener)
removeListener
in interface IPlayer<P extends APlayer>
listener
- param==null -> clear()public void onPrepared()
onPrepared
in interface IPlayerBase.Listener
public void onBufferingUpdate(int percent)
onBufferingUpdate
in interface IPlayerBase.Listener
public P shouldAutoPlayWhenSeekComplete(boolean shouldAutoPlayWhenSeekComplete)
IPlayer
*IPlayerBase.start()
method with shouldAutoPlayWhenSeekComplete(true) *IPlayerBase.pause()
with shouldAutoPlayWhenSeekComplete(false)
shouldAutoPlayWhenSeekComplete
in interface IPlayer<P extends APlayer>
public void onSeekComplete()
onSeekComplete
in interface IPlayerBase.Listener
public int onCompletion()
onCompletion
in interface IPlayerBase.Listener
C.CMD_RETURN_FORCED
/C.CMD_RETURN_NORMAL
public boolean onInfo(int what, int extra)
onInfo
in interface IPlayerBase.Listener
public boolean onError(int what, int extra, java.lang.Exception e)
onError
in interface IPlayerBase.Listener
public void onVideoSizeChanged(int width, int height, int unappliedRotationDegrees, float pixelWidthHeightRatio)
onVideoSizeChanged
in interface IPlayerBase.Listener
public void onStateChanged(int playbackState)
IPlayerBase.Listener
IPlayerBase.getPlaybackState()
changes.onStateChanged
in interface IPlayerBase.Listener
protected boolean onIntent(android.content.Intent intent)
protected boolean onPlayProgress(long position, long duration)
protected void onPositionUnitProgress(long position, int posUnitIndex, int posUnitState)
protected void onABProgress(long position, long duration, int abState)
protected void onNotificationRequired(int order)
protected boolean onAudioFocusChange(int focusChange)
public P setUpdatePlayProgressDelayMs(long updatePlayProgressDelayMs)
IPlayer
setUpdatePlayProgressDelayMs
in interface IPlayer<P extends APlayer>
updatePlayProgressDelayMs
- value>=0?value:default[1000 - (position % 1000)]protected boolean updatePlayProgressInterruptConditions()
protected void updatePlayProgress(int updatePlayProgressCommand)
updatePlayProgressCommand
- public P setPositionUnitList(IPositionUnitList posUnitList)
IPlayer
IPositionUnitList.getMediaId()
equals IPlayer.getCurrentMediaId()
can work normallysetPositionUnitList
in interface IPlayer<P extends APlayer>
posUnitList
- [Position Unit] Listprotected boolean posUnitListAvailable()
public int getCurrentPositionUnitIndex()
getCurrentPositionUnitIndex
in interface IPlayer<P extends APlayer>
public void setCurrentPositionUnitIndex(int posUnitIndex)
IPlayer
If you want to calibrate,can call IPlayer.calibrateCurrentPositionUnitIndex(long)
setCurrentPositionUnitIndex
in interface IPlayer<P extends APlayer>
protected boolean positionUnitProgress(long position)
position
- current play positionpublic long seekToPositionUnitIndex(int posUnitIndex)
IPlayer
seekToPositionUnitIndex
in interface IPlayer<P extends APlayer>
public int calibrateCurrentPositionUnitIndex(long position)
IPlayer
calibrateCurrentPositionUnitIndex
in interface IPlayer<P extends APlayer>
position
- currentPosition or -1[position < 0 || position > getDuration()] (auto
getCurrentPosition())protected void setPositionUnitLoop(int loopMode, int loopInterval)
public P setPositionUnitLoopIndexList(java.util.ArrayList<java.lang.Integer> posUnitLoopIndexList)
IPlayer
setPositionUnitLoopIndexList
in interface IPlayer<P extends APlayer>
posUnitLoopIndexList
- specify to loop of [position unit] index listpublic P setEnabledPositionUnitLoop(boolean enabled, int loopMode, int loopInterval)
IPlayer
C.PARAM_ORIGINAL
keeping
the original values *param loopMode,loopInterval can use C.PARAM_UNSET
/C.PARAM_RESET
unset/reset valuessetEnabledPositionUnitLoop
in interface IPlayer<P extends APlayer>
enabled
- True [position unit] loop is enabled, false otherwise.loopMode
- [Position unit] loop mode loopInterval
- [Position unit] loop intervalIPlayer.setUpdatePlayProgressDelayMs(long)
protected int positionUnitLoopProcessing(int processFrom)
processFrom
- public P setAB(long startPos, long endPos)
IPlayer
setAB
in interface IPlayer<P extends APlayer>
startPos
- [A-B] start position (Ms)endPos
- [A-B] end position (Ms)IPlayer
!setAB but does not play. You must call play(?) to play.IPlayer.play()
,
IPlayer.play(Uri)
public P setABLoop(int loopMode, int loopInterval)
IPlayer
C.PARAM_ORIGINAL
keeping the
original values *param loopMode,loopInterval can use C.PARAM_UNSET
/C.PARAM_RESET
unset/reset valuessetABLoop
in interface IPlayer<P extends APlayer>
loopMode
- [A-B] loop mode loopInterval
- [A-B] loop interval (S)IPlayer
!setAB but does not play. You must call play(?) to play.IPlayer.play()
,
IPlayer.play(Uri)
public P setAB(long startPos, long endPos, int loopMode, int loopInterval)
IPlayer
IPlayer.setAB(long, long)
, IPlayer.setABLoop(int, int)
*param loopMode,loopInterval can use C.PARAM_ORIGINAL
keeping the original values
*param loopMode,loopInterval can use C.PARAM_UNSET
/C.PARAM_RESET
unset/reset valuessetAB
in interface IPlayer<P extends APlayer>
startPos
- [A-B] start position (Ms)endPos
- [A-B] end position (Ms)loopMode
- [A-B] loop mode loopInterval
- [A-B] loop interval (S)IPlayer
!setAB but does not play. You must call play(?) to play.IPlayer.play()
,
IPlayer.play(Uri)
public P setClearAB(boolean autoClear)
IPlayer
setClearAB
in interface IPlayer<P extends APlayer>
IPlayer.clearAB()
public void clearAB()
IPlayer
clearAB
in interface IPlayer<P extends APlayer>
IPlayer.setClearAB(boolean)
protected boolean abProgress(long position)
position
- current play positionprotected int abLoopProcessing(int processFrom)
processFrom
- public void setMediaQueue(IMediaQueue mediaQueue)
IPlayer
setMediaQueue
in interface IPlayer<P extends APlayer>
mediaQueue
- IMediaQueue
public IMediaQueue getMediaQueue()
IPlayer
IPlayer.setMediaQueue(IMediaQueue)
, it return default media queuegetMediaQueue
in interface IPlayer<P extends APlayer>
IMediaQueue
public java.lang.String getCurrentMediaId()
IPlayer
getCurrentMediaId
in interface IPlayer<P extends APlayer>
public P setEnabledWifiLock(boolean enabled)
IPlayer
<!--Using a WifiLock For KMedia Player--> <uses-permission android:name="android.permission.WAKE_LOCK"/>
setEnabledWifiLock
in interface IPlayer<P extends APlayer>
public P setEnabledAudioFocusManage(boolean enabled)
setEnabledAudioFocusManage
in interface IPlayer<P extends APlayer>
public AudioMgrHelper getAudioMgrHelper()
getAudioMgrHelper
in interface IPlayer<P extends APlayer>
private void tryToGetAudioFocus()
private void giveUpAudioFocus()
protected boolean configureAudioFocus()
protected APlayer.ComponentListener getComponentListener()
protected void registerComponentReceiver()
protected void unregisterComponentReceiver()
protected android.content.IntentFilter getComponentIntentFilter()
protected APlayer.ComponentReceiver getComponentReceiver()
public void supportBaseOnContextOfFunctionModule(@NonNull android.content.Context context)
context
- Use for internal register/unregisterReceiver, getSystemService, ...