public class ProgressClock
extends java.lang.Object
限定符和类型 | 类和说明 |
---|---|
static interface |
ProgressClock.Callback
回调接口。
|
构造器和说明 |
---|
ProgressClock(boolean countDown,
ProgressClock.Callback callback)
创建一个 ProgressClock 对象。
|
ProgressClock(ProgressClock.Callback callback)
创建一个 ProgressClock 对象。
|
限定符和类型 | 方法和说明 |
---|---|
static java.lang.String |
asText(int seconds)
将歌曲的播放进度格式化成一个形如 “00:00” 的字符串,方便在 UI 上显示。
|
void |
cancel() |
boolean |
isCountDown()
是否是倒计时时钟。
|
boolean |
isEnabled()
判断是否启用了进度条时钟。
|
void |
setEnabled(boolean enabled)
设置是否启用进度条时钟。
|
void |
setSpeed(float speed)
设置速度倍数。
|
void |
start(int progress,
long updateTime,
int duration)
启动定时器。
|
void |
start(int progress,
long updateTime,
int duration,
float speed)
启动定时器。
|
public ProgressClock(@NonNull ProgressClock.Callback callback)
默认处于启用状态,非倒计时。
callback
- 回调接口,用于接收 progress 值的更新,不能为 nullisEnabled()
,
setEnabled(boolean)
public ProgressClock(boolean countDown, @NonNull ProgressClock.Callback callback)
countDown
- 是否是倒计时callback
- 回调接口,用于接收 progress 值的更新,不能为 nullisEnabled()
,
setEnabled(boolean)
public boolean isEnabled()
如果返回 false,则会忽略对 start(int, long, int, float)
方法的调用
public boolean isCountDown()
public void setEnabled(boolean enabled)
如果参数为 false,则会忽略对 start(int, long, int, float)
方法的调用。
enabled
- 是否启用进度条时钟public void setSpeed(float speed)
speed
- 速度倍数(默认为 1.0F)。public void start(int progress, long updateTime, int duration)
SystemClock.elapsedRealtime()
的。progress
- 歌曲的播放进度(单位:毫秒)updateTime
- 歌曲播放进度的更新时间(单位:毫秒)duration
- 歌曲的持续时间(单位:毫秒)java.lang.IllegalArgumentException
- 在 updateTime 大于当前时间时抛出该异常public void start(int progress, long updateTime, int duration, float speed) throws java.lang.IllegalArgumentException
SystemClock.elapsedRealtime()
的。progress
- 歌曲的播放进度(单位:毫秒)updateTime
- 歌曲播放进度的更新时间(单位:毫秒)duration
- 歌曲的持续时间(单位:毫秒)speed
- 速度系数java.lang.IllegalArgumentException
- 在 updateTime 大于当前时间时抛出该异常public void cancel()
public static java.lang.String asText(int seconds)
格式化后的字符串的格式为:[时:分:秒](例如:01:30:45)。如果 “时” 为 0, 则会忽略, 此时的字符串格式 是:[分:秒](例如:04:35)。最多支持到 99:59:59, 如果 seconds 参数的值大于等于 359,999(99:59:59) 时, 会直接返回 99:59:59。
seconds
- 歌曲的播放进度,单位:秒