Pass AudioAttributes on L+ when vibrating

This commit is contained in:
Cameron Gutman 2019-03-02 17:20:39 -08:00
parent 0c1451f757
commit 1137c74f76

View File

@ -1106,7 +1106,15 @@ public class ControllerHandler implements InputManager.InputDeviceListener, UsbD
long pwmPeriod = 20; long pwmPeriod = 20;
long onTime = (long)((simulatedAmplitude / 255.0) * pwmPeriod); long onTime = (long)((simulatedAmplitude / 255.0) * pwmPeriod);
long offTime = pwmPeriod - onTime; long offTime = pwmPeriod - onTime;
vibrator.vibrate(new long[]{0, onTime, offTime}, 0); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
AudioAttributes audioAttributes = new AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_GAME)
.build();
vibrator.vibrate(new long[]{0, onTime, offTime}, 0, audioAttributes);
}
else {
vibrator.vibrate(new long[]{0, onTime, offTime}, 0);
}
} }
public void handleRumble(short controllerNumber, short lowFreqMotor, short highFreqMotor) { public void handleRumble(short controllerNumber, short lowFreqMotor, short highFreqMotor) {