#
OGG Files (Android)
Android devices with level 3 haptics support can play haptic feedback encoded in OGG Vorbis audio files. This allows to create haptic feedback that is synchronized with audio playback, both stored in the same file.
#
Structure
Haptic-enabled OGG files (as exported from Hapticlabs Studio) contain three channels:
- Audio (left channel)
- Audio (right channel)
- Haptics
To identify to Android's MediaPlayer
that the OGG file contains haptic feedback, the file needs to contain the following Vorbis comment:
The value of the ANDROID_HAPTIC
field represents the count of haptic channels in the file (documentation).
The easiest way to obtain correctly structured OGG files is to export them from Hapticlabs Studio. To synchronize audio and haptic feedback, use the stereo track feature in Hapticlabs Studio.
#
Playback
#
React Native
The react-native-hapticlabs
npm package provides a simple way to play back OGG files with haptic feedback on Android devices.
import { playOGG } from 'react-native-hapticlabs';
// Play an OGG file with haptic feedback
playOGG('path/to/file.ogg');
#
Kotlin
To play back an OGG file with haptic feedback on an Android device, use our hapticlabsplayer
Android library:
import io.hapticlabs.hapticlabsplayer.HapticlabsPlayer
// Instantiate the player
val hapticlabsPlayer = remember { HapticlabsPlayer(context) }
// Play OGG file with haptic feedback
hapticlabsPlayer.playOGG(
"path/to/file.ogg",
completionCallback = { println("completed playback") })