public abstract static class PlayerService.NotificationView
extends java.lang.Object
限定符和类型 | 类和说明 |
---|---|
static interface |
PlayerService.NotificationView.BetterIconLoader
用于加载
MusicItem 对象的 Icon 图片。 |
static class |
PlayerService.NotificationView.IconLoader
已过时。
|
限定符和类型 | 字段和说明 |
---|---|
static java.lang.String |
CHANNEL_ID
通知的 channelId 值,值为:
"player" |
构造器和说明 |
---|
NotificationView() |
限定符和类型 | 方法和说明 |
---|---|
void |
addCustomAction(java.lang.String action,
PlayerService.CustomAction customAction)
添加自定义动作。
|
android.app.PendingIntent |
buildCustomAction(java.lang.String actionName,
PlayerService.CustomAction customAction)
构建一个可附件到通知控件上的 PendingIntent 自定义动作。
|
java.lang.CharSequence |
getContentText(java.lang.String contentText)
工具方法,在
PlaybackState.ERROR 状态时,会返回一个
android.R.color.holo_red_dark 颜色的描述错误信息的 CharSequence 对象;其它状态下会将
defaultValue 原值返回。 |
android.content.Context |
getContext()
获取 Context 对象。
|
android.graphics.Bitmap |
getDefaultIcon() |
java.lang.String |
getErrorMessage()
获取错误信息。
|
android.graphics.Bitmap |
getIcon()
获取当前通知栏控制器的图标。
|
android.support.v4.media.session.MediaSessionCompat |
getMediaSession()
获取当前播放器的
MediaSessionCompat 对象。 |
abstract int |
getNotificationId()
返回 Notification 的 ID。
|
java.lang.String |
getPackageName()
获取当前应用的包名。
|
PlaybackState |
getPlaybackState()
获取播放器的播放状态。
|
MusicItem |
getPlayingMusicItem()
获取当前正在播放的音乐的 MusicItem 对象。
|
android.os.Bundle |
getPlaylistExtra()
获取播放队列携带的额外参数(可为 null)。
|
PlayMode |
getPlayMode()
获取播放器的播放模式。
|
void |
invalidate()
要求 Service 更新 NotificationView,如果没有设置 NotificationView,则忽略本次操作。
|
boolean |
isError()
播放器是否发生了错误。
|
boolean |
isExpire()
通知是否已经过期。
|
boolean |
isPlayingState()
当前是否正在播放音乐。
|
boolean |
isPrepared()
播放器是否已准备完毕。
|
boolean |
isPreparing()
播放器当前是否处正在准备中。
|
boolean |
isReleased()
检查
PlayerService.NotificationView 是否已被释放。 |
boolean |
isStalled()
判断当前播放器是否处于
stalled 状态。 |
protected PlayerService.NotificationView.BetterIconLoader |
onCreateBetterIconLoader(android.content.Context context) |
protected PlayerService.NotificationView.IconLoader |
onCreateIconLoader(android.content.Context context)
已过时。
|
abstract android.app.Notification |
onCreateNotification()
创建一个新的 Notification 对象,不能为 null。
|
protected void |
onInit(android.content.Context context)
该方法会在初次创建 NotificationView 对象时调用,你可以重写该方法来进行一些初始化操作。
|
protected void |
onPlayModeChanged(PlayMode playMode)
该方法会在播放模式发生改变时调用。
|
protected void |
onRelease()
该方法会在 Service 销毁时调用,可以在该方法中释放占用的资源。
|
void |
setDefaultIcon(android.graphics.Bitmap bitmap) |
void |
setIcon(android.graphics.Bitmap icon)
设置当前通知栏控制器的图标。
|
void |
setIconSize(int size)
设置图标的尺寸(默认尺寸为 0)。
|
void |
setIconSize(int width,
int height)
分别设置图标的宽高尺寸(默认宽高为 0)。
|
void |
shutdown()
关闭播放器。
|
public static final java.lang.String CHANNEL_ID
"player"
protected void onInit(android.content.Context context)
@Deprecated @NonNull protected PlayerService.NotificationView.IconLoader onCreateIconLoader(@NonNull android.content.Context context)
PlayerService.NotificationView.IconLoader
对象。
如果子类想要实现自定义的图片加载逻辑,则可以覆盖该方法来提供一个自定义的 PlayerService.NotificationView.IconLoader
。
context
- Context 对象,不为 nullPlayerService.NotificationView.IconLoader
对象,不能为 null@NonNull protected PlayerService.NotificationView.BetterIconLoader onCreateBetterIconLoader(@NonNull android.content.Context context)
protected void onPlayModeChanged(@NonNull PlayMode playMode)
playMode
- 当前播放模式。protected void onRelease()
public final android.app.PendingIntent buildCustomAction(java.lang.String actionName, PlayerService.CustomAction customAction)
actionName
- 自定义动作名称。customAction
- 自定义动作被触发时要执行的任务。@NonNull public abstract android.app.Notification onCreateNotification()
public abstract int getNotificationId()
public final void shutdown()
public final android.graphics.Bitmap getIcon()
public final void setIcon(@NonNull android.graphics.Bitmap icon)
调用该方法后会自动更新通知栏控制器,以应用最新设置的图标。
public final void setIconSize(int size)
建议子类覆盖 onInit(Context)
方法,并在该方法中完成图标尺寸的设置。
public final void setIconSize(int width, int height)
建议子类覆盖 onInit(Context)
方法,并在该方法中完成图标宽高尺寸的设置。
public final void setDefaultIcon(@NonNull android.graphics.Bitmap bitmap)
@NonNull public final android.graphics.Bitmap getDefaultIcon()
public final java.lang.CharSequence getContentText(java.lang.String contentText)
PlaybackState.ERROR
状态时,会返回一个
android.R.color.holo_red_dark
颜色的描述错误信息的 CharSequence 对象;其它状态下会将
defaultValue
原值返回。contentText
- context text 的值,如果播放器处于正常播放器状态,该方法会将这个值原样返回,
如果播放器正发生了错误,则将返回一个提示字符串public final android.content.Context getContext()
public final java.lang.String getPackageName()
public final PlayMode getPlayMode()
@Nullable public final android.os.Bundle getPlaylistExtra()
public final void addCustomAction(@NonNull java.lang.String action, @NonNull PlayerService.CustomAction customAction)
action
- 自定在动作的名称,请保证该值的唯一性customAction
- 要执行的任务public final boolean isPreparing()
public final boolean isPrepared()
public final boolean isStalled()
stalled
状态。true
,否则返回 false@NonNull public final PlaybackState getPlaybackState()
public final boolean isPlayingState()
public final boolean isError()
@NonNull public final java.lang.String getErrorMessage()
该方法的返回值仅在发生错误(isError()
方法返回 true)时才有意义。
public final boolean isReleased()
PlayerService.NotificationView
是否已被释放。PlayerService.NotificationView
的任何方法。@NonNull public final MusicItem getPlayingMusicItem()
public final android.support.v4.media.session.MediaSessionCompat getMediaSession()
MediaSessionCompat
对象。MediaSessionCompat
对象public final boolean isExpire()
通知会在当前正在播放的音乐改变时过期。你可以在 onCreateNotification()
方法中调用该方法检测当前通知是否已过期,如果已过期,
则你应该重新获取与当前正在播放的歌曲相关的信息,例如重新获取歌曲的封面图片。
public final void invalidate()