API reference
API reference
Select your platform
No SDKs available
No versions available

HapticClipPlayer Class

Extends IDisposable
HapticClipPlayer provides controls for playing a HapticClip.
A HapticClipPlayer only plays valid HapticClips. You can start and stop a HapticClip assigned to a HapticClipPlayer as often as required. The rendered amplitude and frequency can be modulated during runtime using the HapticClipPlayer.amplitude and HapticClipPlayer.frequencyShift properties respectively. You can also loop a clip using the HapticClipPlayer.isLooping property. It is possible to release HapticClipPlayer objects as needed to free up memory using the Dispose() method. Of course, calling any method on a released HapticClipPlayer will cause a runtime error.

Protected Fields

The implementation of Haptics for HapticClipPlayer to use. This field is protected to allow derived classes to provide a custom implementation. The HapticClipPlayer uses this instance to play haptic clips and access haptic-related functionality.

Properties

Whether looping is enabled or not. When set to true, the haptic clip will loop continuously until stopped.
true if looping is enabled.
Sets/gets the HapticClipPlayer's amplitude.
During playback, the individual amplitudes in the clip will be multiplied by the player's amplitude. This changes how strong the vibration is. Amplitude values in a clip range from 0.0 to 1.0, and the result after applying the amplitude scale will be clipped to that range.An amplitude of 0.0 means that no vibration will be triggered, and an amplitude of 0.5 will result in the clip being played back at half of its amplitude.Example: if you apply amplitude of 5.0 to a haptic clip and the following amplitudes are in the clip: [0.2, 0.5, 0.1], the initial amplitude calculation would produce these values: [1.0, 2.5, 0.5] which will then be clamped like this: [1.0, 1.0, 0.5]This method can be called during active playback, in which case the amplitude is applied immediately, with a small delay in the tens of milliseconds. A value of zero or greater. Negative values will cause an exception.
Sets/gets the HapticClipPlayer's frequency shift.
The frequencies in a haptic clip are in the range zero to one. This property shifts the individual frequencies up or down. The acceptable range of values is -1.0 to 1.0 inclusive.Once the frequencies in a clip have been shifted, they will be clamped to the playable range of frequency values, i.e. zero to one.Setting this property to 0.0 means that the frequencies will not be changed.Example: if you apply a frequency shift of 0.8 to a haptic clip and the following frequencies are in the clip: [0.1, 0.5, 0.0], the initial frequency shift calculation will produce these frequencies: [0.9, 1.3, 0.8] which will then be clamped like this: [0.9, 1.0, 0.8]This method can be called during active playback, in which case the frequency shift is applied immediately, with a small delay in the tens of milliseconds. A value between -1.0 and 1.0. Values outside this range will cause an exception.
Sets/gets the HapticClipPlayer's playback priority.
The playback engine of the Haptics SDK only ever renders the vibrations of a single HapticClipPlayer clip on the same controller at the same time. Meaning, haptic clips are not "mixed" when played back. If you have multiple players playing on the same controller at the same time, then only the player with the highest priority will trigger vibrations.Given the same priority value, the engine will always play the most recent clip that was started. All other players are muted, but continue tracking playback on their respective timeline (i.e. they are not paused). If a clip finishes (or is stopped), the engine will resume playback of the second most recent clip with an equal or higher priority level and so on.Example: Setting priority can be helpful if some haptic clips are more important than others, and allow us to design a hierarchy of haptic feedback based on context or the overall importance. For example, we could want a user to always receive a distinct haptic feedback if they are hit. Setting this "hit" clips priority higher compared to other haptic clips will ensure that the user always receives this haptic feedback.Priority values can be on the range of 0 (high priority) to 255 (low priority). By default, the priority value is set to 128 for every HapticClipPlayer. The player's priority can be changed before and during playback. An integer value within the range 0 to 255 (inclusive). Values outside this range will cause an exception.
Sets the HapticClipPlayer's current haptic clip.
This feature allows you to change the clip loaded in a clip player. If the player is currently playing it will be stopped. All other properties like amplitude, frequency shift, looping and priority are kept. A valid, JSON formatted, UTF-8 encoded haptic clip. Providing invalid clip data will cause an exception.

Fields

Gets the duration of the loaded haptic clip of this HapticClipPlayer's instance.
The duration of the haptic clip in seconds.This property returns the length of the haptic clip in seconds. If no haptic clip is loaded, this property will return 0.

Member Functions

Creates a HapticClipPlayer with no HapticClip assigned to it.
You must assign a HapticClip before you can play this HapticClipPlayer. You can either call the overloaded version of this constructor that accepts a HapticClip or assign it with clip.
Creates a HapticClipPlayer and assigns the given HapticClip to it. You can use this player to play, stop, and generally control the haptic clip's playback properties.
Parameters
clip
The HapticClip to be played by this HapticClipPlayer. Providing invalid clip data (e.g., null or empty) will throw an ArgumentNullException.
Starts playing the assigned haptic clip on the specified controller.
Parameters
controller
The controller(s) to play back on. See Haptics.Controller
Stops playback of the HapticClipPlayer. If a haptic clip is currently playing, it will be stopped immediately. You can call this method at any time to stop playback, regardless of whether a clip is currently playing or not.
Call this method to explicitly/deterministically release a HapticClipPlayer object, otherwise the garbage collector will release it. Of course, any calls to a disposed HapticClipPlayer will result in runtime errors.
A given HapticClip will not be freed until all HapticClipPlayers to which it is assigned have also been freed.

Protected Functions

Sets the Haptics implementation that HapticClipPlayer will call into for all haptics operations. See also: Haptics.Instance for more information on Haptics.
Releases the assigned clip and clip player from memory.
Did you find this page helpful?
Thumbs up icon
Thumbs down icon