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
1 Answers
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.
-
Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 07 '22 at 06:29
-
Yep, you are right. I have tried the HapticGenrater and it work, but that isn't my want. As for ogg, I also have tried to play different ogg file with haptic data and specfied metedata, but it didn't work, I can't ensure that my configuration is correct. Could you give a more detailed description or a simple ogg sample file? Thank you very much. – Mu San Nov 19 '22 at 19:41
-
Maybe you want to try the ogg file from Android CTS. See the following link as an example. https://cs.android.com/android/platform/superproject/+/master:cts/tests/tests/media/audio/res/raw/a_4_haptic.ogg – Huang Flamme Dec 06 '22 at 06:47