Most visited

Recently visited

Added in API level 21

PlaybackState.Builder

public static final class PlaybackState.Builder
extends Object

java.lang.Object
    android.media.session.PlaybackState.Builder


PlaybackState对象的生成器。

摘要(Summary)

Public constructors

PlaybackState.Builder()

创建最初为空的状态构建器。

PlaybackState.Builder(PlaybackState from)

创建一个具有与from状态相同的初始值的构建器。

公共方法(Public methods)

PlaybackState.Builder addCustomAction(String action, String name, int icon)

将自定义操作添加到播放状态。

PlaybackState.Builder addCustomAction(PlaybackState.CustomAction customAction)

将自定义操作添加到播放状态。

PlaybackState build()

使用这些值构建并返回 PlaybackState实例。

PlaybackState.Builder setActions(long actions)

设置此会话中可用的当前操作。

PlaybackState.Builder setActiveQueueItemId(long id)

通过指定其ID,将活动项目设置在播放队列中。

PlaybackState.Builder setBufferedPosition(long bufferedPosition)

以ms为单位设置当前缓冲位置。

PlaybackState.Builder setErrorMessage(CharSequence error)

设置用户可读的错误消息。

PlaybackState.Builder setExtras(Bundle extras)

设置任何自定义附加功能以包含在播放状态中。

PlaybackState.Builder setState(int state, long position, float playbackSpeed)

设置播放的当前状态。

PlaybackState.Builder setState(int state, long position, float playbackSpeed, long updateTime)

设置播放的当前状态。

继承方法(Inherited methods)

From class java.lang.Object

Public constructors

PlaybackState.Builder

Added in API level 21
PlaybackState.Builder ()

创建最初为空的状态构建器。

PlaybackState.Builder

Added in API level 21
PlaybackState.Builder (PlaybackState from)

创建一个具有与from状态相同的初始值的构建器。

参数(Parameters)
from PlaybackState: The state to use for initializing the builder.

公共方法(Public methods)

addCustomAction

Added in API level 21
PlaybackState.Builder addCustomAction (String action, 
                String name, 
                int icon)

将自定义操作添加到播放状态。 除了标准传输控制提供的功能之外,可以使用操作向MediaControllers公开其他功能。

例如根据当前项目启动广播电台或跳过30秒。

参数(Parameters)
action String: An identifier for this action. It can be sent back to the MediaSession through sendCustomAction(String, Bundle).
name String: The display name for the action. If text is shown with the action or used for accessibility, this is what should be used.
icon int: The resource action of the icon that should be displayed for the action. The resource should be in the package of the MediaSession.
返回(Returns)
PlaybackState.Builder this

addCustomAction

Added in API level 21
PlaybackState.Builder addCustomAction (PlaybackState.CustomAction customAction)

将自定义操作添加到播放状态。 除了标准传输控制提供的功能之外,还可以使用操作向MediaControllers提供其他功能。

一个举措的例子是根据当前项目启动广播电台或跳过30秒。

参数(Parameters)
customAction PlaybackState.CustomAction: The custom action to add to the PlaybackState.
返回(Returns)
PlaybackState.Builder this

build

Added in API level 21
PlaybackState build ()

使用这些值构建并返回 PlaybackState实例。

返回(Returns)
PlaybackState A new state instance.

setActiveQueueItemId

Added in API level 21
PlaybackState.Builder setActiveQueueItemId (long id)

通过指定其ID,将活动项目设置在播放队列中。 默认值是UNKNOWN_ID

参数(Parameters)
id long: The id of the active item.
返回(Returns)
PlaybackState.Builder this

setBufferedPosition

Added in API level 21
PlaybackState.Builder setBufferedPosition (long bufferedPosition)

以ms为单位设置当前缓冲位置。 这是可以使用缓冲内容从当前位置到达的最远的播放点。

参数(Parameters)
bufferedPosition long: The position in ms that playback is buffered to.
返回(Returns)
PlaybackState.Builder this

setErrorMessage

Added in API level 21
PlaybackState.Builder setErrorMessage (CharSequence error)

设置用户可读的错误消息。 当状态为STATE_ERROR时,应该设置此STATE_ERROR

参数(Parameters)
error CharSequence: The error message for display to the user.
返回(Returns)
PlaybackState.Builder this

setExtras

Added in API level 22
PlaybackState.Builder setExtras (Bundle extras)

设置任何自定义附加功能以包含在播放状态中。

参数(Parameters)
extras Bundle: The extras to include.
返回(Returns)
PlaybackState.Builder this

setState

Added in API level 21
PlaybackState.Builder setState (int state, 
                long position, 
                float playbackSpeed)

设置播放的当前状态。

该位置必须以毫秒为单位,并表示该项目内的当前播放位置。 如果位置未知,请使用PLAYBACK_POSITION_UNKNOWN 更新时间将设置为当前elapsedRealtime()

速度是正常播放的倍数,暂停时为0,倒带时为负。 正常播放速度为1.0。

国家必须是以下之一:

参数(Parameters)
state int: The current state of playback.
position long: The position in the current item in ms.
playbackSpeed float: The current speed of playback as a multiple of normal playback.
返回(Returns)
PlaybackState.Builder this

setState

Added in API level 21
PlaybackState.Builder setState (int state, 
                long position, 
                float playbackSpeed, 
                long updateTime)

设置播放的当前状态。

该位置必须以毫秒为单位,并表示该项目内的当前播放位置。 如果位置未知,请使用PLAYBACK_POSITION_UNKNOWN 不使用未知位置时,必须提供位置更新的时间。 如果刚刚检索到当前位置,则可以使用elapsedRealtime()

速度是正常播放的倍数,暂停时为0,倒带时为负。 正常播放速度为1.0。

国家必须是以下之一:

参数(Parameters)
state int: The current state of playback.
position long: The position in the current item in ms.
playbackSpeed float: The current speed of playback as a multiple of normal playback.
updateTime long: The time in the elapsedRealtime() timebase that the position was updated at.
返回(Returns)
PlaybackState.Builder this

Hooray!