You do not have to install a Feel library. The exported file contains all of the code. Your app must use Media3 to play the video.
-
Export with the Kotlin playback code format. See Export haptics.
-
Copy
FeelHapticVideoSync.ktto your source folder. Use this folder:app/src/main/java/com/feelplayer/haptics/ -
Copy
<project>.jsonto the assets folder. If the folder does not exist, create it:app/src/main/assets/ -
In
app/build.gradle.kts, add Media3:dependencies { implementation("androidx.media3:media3-exoplayer:1.8.0") } -
In
AndroidManifest.xml, add this permission:<uses-permission android:name="android.permission.VIBRATE" />
-
Import the class in your activity:
import com.feelplayer.haptics.HapticVideoSync
-
Create the sync object after you create the player. Use the full name of your file, with the extension:
val player = ExoPlayer.Builder(this).build() val haptics = HapticVideoSync.fromAsset(this, player, "<project>.json") player.setMediaItem(MediaItem.fromUri(videoUri)) player.prepare() player.play()
-
Keep a reference to
hapticswhile the video plays. -
When you close the screen, release the two objects in this sequence:
haptics.release() player.release()
The haptics follow play, pause, buffering, seek, and speed changes. If the file is not a Feel haptics file, fromAsset throws IllegalArgumentException. If the file does not contain valid JSON, or does not have a list of events, fromAsset throws JSONException. If the file is not in the assets folder, fromAsset throws FileNotFoundException. Use haptics.isSupported to find out if the device has a vibration motor.
Note
The Media vibration setting on the device controls the strength of these haptics. If the user sets it to off, the haptics do not operate. On a Pixel, this setting is in Settings > Sound & vibration > Vibration & haptics. The name and location can be different on other devices.
A system vibration, such as a touch vibration, can stop the haptics for a maximum of 1.5 seconds. The haptics then start again automatically.