I'm trying to develop an application to play the audio with my haptic data. I can realize the haptic effect of HapticGenerator on Pixel 4 XL. but I can't understand the section Audio-coupled haptics: Tips for implementing in the guidance. How should I generate the special OGG file and write the implementation code?

1

There are 1 best solutions below

3
Huang Flamme On

There are two ways to explore audio+haptic and Android. One is using HapticGenerator which you can just attach the effect to your playback and the effect will generate haptic data from your audio data. Another one is using OGG file. As mentioned in Audio-coupled haptics: Tips for implementing, you will need to put your audio and haptic data in the same ogg file where haptic will be extra channels besides audio channels. For instance, you have stereo audio and one haptic channel data, you then will have stereo audio at the first two channel and haptic data at the third channel. And then you will need to specify the haptic channel count via ANDROID_HAPTIC in the metadata. Given Android only supports up to two haptic channels, any values greater than 2 will be invalid. When playing such an OGG file using MediaPlayer, you will need to call MediaPlayer.setAudioAttributes(new AudioAttributes.Builder( ).setHapticChannelsMuted(false)) to unmute haptic channels.