Link Search Menu Expand Document

Playing Haptic Clips

🔥NOTE: The Studio library for Android is currently in beta and under development. Information on this page is subject to change.

Haptic clips are created with either the Studio desktop app or the Studio web app. A haptic clip contains high-definition, device-agnostic haptic data that the Studio library for Android uses to create an optimal haptic effect on playback devices. The playback of these haptic clips requires only three simple steps:

  1. Load the haptic clip into the LofeltHaptics object with the load() method.
  2. Start playback of the haptic clip with the play() method.
  3. Stop playback of the haptic clip with the stop() method (which is only needed when you wish to stop the haptic clip before it has finished playing).

Load

public void load(byte[] clip)

The load() method allows you to load the contents of a haptic clip into memory before triggering playback with play().

Play

public void play()

The play() method initiates haptic playback of the haptic clip currently loaded into the LofeltHaptics instance.

Playback of the haptic effect always starts from the beginning of the haptic clip and automatically stops when playback reaches the end of the haptic clip. However, you can stop playback of the haptic effect prematurely with the stop() method.

Stop

public void stop()

If a LofeltHaptics object is currently playing a haptic clip, the stop() method terminates playback. If a haptic clip is not playing, the stop() method will have no effect.

Using the stop() method leaves the currently loaded haptic clip in memory. A subsequent play() method will play the same haptic clip again starting from the beginning.

Code Example

LofeltHaptics haptics = new LofeltHaptics(this);

try {
	// Load haptic clip
	final InputStream stream = getResources().openRawResource(hapticClipResourceId);
	final byte[] hapticClipBytes = IOUtils.toByteArray(stream);
	haptics.load(hapticClipBytes);

	// Play haptic clip
	haptics.play();
} catch (Exception e) {
 	// ...
}

In this example, the haptic clip is loaded from an Android resource (of course, you can load it in any way you prefer).

Example Project

In the sdk/examples/android folder within the Lofelt Studio download, there is an example project for playing haptic clips on a phone called LofeltHapticsExamplePreAuthored. To run the example, open the project in Android Studio, target your phone, and build. The example provides two buttons that, when pressed and released, will trigger playback of audio files and accompanying haptic clips.

< Prev Next >


Copyright © 2020-2021 Lofelt GmbH. All rights reserved.