Building an Android Video Player That Vibrates in Sync
Most video players treat the phone's vibration motor as an afterthought. Games use it well, but when you watch a film or a clip, a gunshot or an explosion reaches you only through the speaker. I wanted a player where the phone itself reacts: a light pulse for a quiet moment, a hard double-tap for an impact. The catch is that this has to work on any video, with no hand-authored vibration track. That is what iRThrum does, and this post covers how it is built and what the design taught me.
Why I built it
I build Android apps and tools as side projects, and I was curious how far automatic haptics could go if the app simply listened to what was playing and watched what was on screen. No beat-mapping, no manual sync, no preprocessing step: pick a video, press play, and the phone responds. The interesting engineering problem turned out not to be the player, which is just ExoPlayer, but getting at the decoded audio and the current frame in real time without disturbing playback.
What it does
You pick a video from your device and iRThrum plays it with Media3 ExoPlayer while a haptic engine converts what it detects into vibration. There are three kinds of trigger:
- Beats: sustained loudness rising above its recent baseline, such as music, emphasised dialogue or ambient swells, fires a single pulse. The amplitude scales with how loud that moment is, so a quiet passage barely buzzes and a loud one hits hard.
- Impacts: a sample peak that spikes sharply above its baseline, like gunfire, an explosion or a punch, fires a stronger double-tap "thud-thud" pattern at much higher amplitude.
- Scene flashes: the same double-tap, but triggered by the picture. A camera flash, the flare of an explosion or a hard cut shows up as a sharp frame-to-frame change, whether or not the moment is loud. This can be toggled independently of audio haptics.
A sensitivity slider controls how easily all three trigger and how strong the pulses feel, and it can be changed live while a video plays.
How it works
Tapping the audio pipeline
ExoPlayer decodes audio into PCM buffers before handing them to the audio sink. I wanted to measure those buffers without altering them. The solution has two parts:
HapticRenderersFactoryis a customDefaultRenderersFactorythat overridesbuildAudioSink()to insert a customAudioProcessorinto the pipeline.HapticAudioProcessorsits there as a pass-through tap. For each PCM buffer about to be played it measures the RMS (average loudness) and the peak (loudest single sample), then forwards the buffer unchanged. Audio quality and sync are unaffected.
Using the audio processor hook is the reusable lesson here. Because the measurement happens inside the pipeline that is already feeding the speaker, the haptics are aligned with what you hear, and there is no second decoder or separate analysis pass.
Why both RMS and peak
I track peak separately from average loudness because a gunshot lasts only a few milliseconds. An RMS average smooths it away, so a loud, very short sound barely moves it. Peak catches the spike. So beats come from a fast versus slow loudness average, while impacts come from a separate peak baseline.
The haptic engine
HapticEngine turns the stream of readings into VibrationEffect calls. Beats and impacts each have their own debounce timer, so rapid sequences such as a drum roll or machine-gun fire do not queue up into a long tail of vibration after the sound has ended.
Reading the picture
The visual side runs on a separate thread:
PlayerViewrenders onto aTextureView(app:surface_type="texture_view") instead of the defaultSurfaceView, because onlyTextureViewoffers a synchronous way to read the current frame back as aBitmap.VisualHapticSourcesamples that frame roughly ten times a second, downscaled to 16x9 pixels, and measures the mean per-pixel luminance difference against the previous sample. A big jump means a flash or a cut just happened.- Both sources feed the same
HapticEngine, so a flash and a bang landing together share one debounce timer instead of producing a double buzz.
Downscaling to 16x9 keeps the comparison cheap, and a luminance difference is enough to detect the kind of abrupt change I care about.
Stack
- Kotlin, single activity, View Binding (no Compose)
- Media3 ExoPlayer 1.11.0
- Android Gradle Plugin 9.3.1, Gradle 9.7, Kotlin 2.3.21
minSdk 24,compileSdkandtargetSdk36
The only permission is VIBRATE. Video selection goes through the system file picker (ACTION_GET_CONTENT), so no storage permission is needed.
What I learned
- Measure in the pipeline, not beside it. A pass-through
AudioProcessorgives real-time access to decoded samples with no added latency and no effect on playback. - One metric is not enough. Average loudness hides short transients, so I needed peak as a second signal with its own baseline.
- Merge sources before the output. Routing audio and visual triggers through one engine with shared debouncing avoids double-buzzing when both fire at once.
- Features can cost something even when off. Rendering to a
TextureViewuses a bit more battery thanSurfaceVieweven when scene flashes are disabled, since Media3'sPlayerViewdoes not support swapping surface types at runtime. That was a trade-off I accepted to get frame access. - Hardware limits shape the result. Amplitude control needs API 26 or higher; below that the app falls back to a fixed-strength buzz. And you need a real device to feel anything, since emulators have no vibration motor.
Conclusion
iRThrum is a small project, but it shows how much you can do by hooking into the right place in an existing media pipeline. The source is on GitHub under ikppramesh/irthrum, and a sideloadable debug build of about 12 MB is included in the repository's release folder. There is no Play Store listing yet. To build it yourself you need JDK 17, then run ./gradlew installDebug with a device connected.