目录

HapticPlayer

Class Info

public class HapticPlayer

振动波形播放。

Nested Interface Summary

Qualifier and Type

Class Name and Description

public interface

OnPlayStateListener

播放状态回调接口。

Public Field Summary

Qualifier and Type

Field and Description

public static final int

HAPTIC_STATE_PLAYING

播放状态。

public static final int

HAPTIC_STATE_STOPPED

停止状态。

public static final int

HAPTIC_STATE_COMPLETED

完成状态。

public static final int

HAPTIC_STATE_ERROR

错误状态。

Public Constructor Summary

Constructor Name

HapticPlayer(Context context)

创建HapticPlayer对象。

Public Method Summary

Qualifier and Type

Method Name and Description

public boolean

setHapticWave(HapticAttributes attr, HapticWave wave)

设置波形自定义参数。

public boolean

setHapticWave(HapticAttributes attr, InputStream inputStream)

设置波形配置文件参数。

public void

setLooping(boolean looping)

设置循环状态。

public boolean

isLooping()

查询循环状态。

public boolean

isPlaying()

查询是否正在播放。

public int

play()

开始播放振动波形。

public void

stop()

停止播放振动波形。

public int

getDuration()

获取总的播放时长。

public boolean

setDynamicCurve(int type, int channelId, HapticCurve curve)

设置动态调节。

public void

setOnPlayStateListener(OnPlayStateListener listener)

设置播放状态回调。

Public Fields

[h2]HAPTIC_STATE_PLAYING

Fields

public static final int HAPTIC_STATE_PLAYING

用于描述播放状态的常量。

另请参阅:Constant-values

[h2]HAPTIC_STATE_STOPPED

Fields

HAPTIC_STATE_STOPPED

用于描述停止状态的常量。

另请参阅:Constant-values

[h2]HAPTIC_STATE_COMPLETED

Fields

HAPTIC_STATE_COMPLETED

用于描述完成状态的常量。

另请参阅:Constant-values

[h2]HAPTIC_STATE_ERROR

Fields

HAPTIC_STATE_ERROR

用于描述错误状态的常量。

另请参阅:Constant-values

Public Constructors

[h2]HapticPlayer

Constructor

HapticPlayer(Context context)

创建HapticPlayer对象。

Public Methods

[h2]setHapticWave(HapticAttributes attr, HapticWave wave)

Method

public boolean setHapticWave(HapticAttributes attr, HapticWave wave)

设置波形自定义参数。

Parameters

Name

Description

attr

振动波形属性。通过

{@link com.huawei.hapticsengine.HapticAttributes#setUsage(int)}方法设置振动波形的使用场景。

wave

自定义振动波形。

Returns

Type

Description

boolean

返回通过自定义方式设置马达振动波形结果:

  • true:设置成功
  • false:设置失败

[h2]setHapticWave(HapticAttributes attr, InputStream inputStream)

Method

public boolean setHapticWave(HapticAttributes attr, InputStream inputStream)

设置波形自定义参数。

Parameters

Name

Description

attr

振动波形属性。通过

{@link com.huawei.hapticsengine.HapticAttributes#setUsage(int)}方法设置振动波形的使用场景。

inputStream

读取JSON波形配置文件得到的文件输入流。

Returns

Type

Description

boolean

返回通过波形配置文件方式设置马达振动波形结果:

  • true:设置成功
  • false:设置失败

[h2]setLooping

Method

public void setLooping(boolean looping)

设置循环状态。

Parameters

Name

Description

looping

  • true:设置为循环状态
  • false:设置为非循环状态

[h2]isLooping

Method

public boolean isLooping()

查询循环状态。

Returns

Type

Description

boolean

  • true:循环状态
  • false:非循环状态

[h2]isPlaying

Method

public boolean isPlaying()

查询是否正在播放。

Returns

Type

Description

boolean

  • true:正在播放
  • false:播放停止

[h2]play

Method

public int play()

开始播放振动波形。

Returns

Type

Description

int

返回播放结果。在{@link com.huawei.devices.hapticsengine.HapticPlayer}中用整型常量定义了播放结果。

[h2]stop

Method

public void stop()

停止播放振动波形。

[h2]getDuration

Method

public int getDuration()

获取某个通道总的播放时长。

Returns

Type

Description

int

振动波形播放时长。

[h2]setDynamicCurve

Method

public boolean setDynamicCurve(int type, int channelId, HapticCurve curve)

设置动态调节。

Parameters

Name

DescriptionHapticChannel.HAPTIC_CHANNEL_A

type

表示振动波形动态调节的曲线类型。在{@link com.huawei.devices.hapticsengine.HapticCurve}中用整型常量定义了振动波形曲线类型。例如:用户可通过采用{@code HapticCurve.CURVE_TYPE_INTENSITY}设置曲线类型为动态强度调节。

channelId

表示振动波形通道ID。在{@link com.huawei.devices.hapticsengine.HapticChannel}中用整型常量定义了振动波形通道ID。例如:用户可通过采用{@code HapticChannel.HAPTIC_CHANNEL_A}设置通道ID为通道A。

curve

振动波形曲线信息。

Returns

Type

Description

boolean

  • true:设置动态调节成功
  • false:设置动态调节失败

setOnPlayStateListener

Method

setOnPlayStateListener(OnPlayStateListener listener)

设置播放状态回调。

Parameters

Name

Description

listener

播放状态回调,接收播放错误码。