Home > Blockchain >  Is there a way to pan audio left and right with Expo-AV?
Is there a way to pan audio left and right with Expo-AV?

Time:09-28

I am building a react-native app with expo and I need the audio to only come out of left or right earphones/speakers. I used expo-av to play the sound file. I have searched the expo-av docs for information about panning left and right, but I haven't found anything. Do I need to switch to a different dependency?

CodePudding user response:

Nope, expo-av and react native track player both don't support this functionality. However you can use react-native-sound instead with the following functions.

  1. getPan() : Return the stereo pan position of the audio player (not the system-wide pan), ranging from -1.0 (full left) through 1.0 (full right). The default value is 0.0 (center).

  2. setPan() : value {number} Set the pan, ranging from -1.0 (full left) through 1.0 (full right).

  3. getNumberOfChannels: Return the number of channels (1 for mono and 2 for stereo sound), or -1 before the sound gets loaded.

This package isn't going to work with expo go. So set up a new expo development client with the package included.

  • Related