Code example for ObjectAnimator

Methods: getCurrentPlayTime, getDuration, isRunning, setCurrentPlayTime, setDuration

0
    private void setSamplingRate(float percentage) {
        mSamplingRateValue = percentage;
 
        if (mAudioEngine != null) {
            mAudioEngine.setSamplingRate(mSamplingRateValue);
            if (mSlotAnimation != null && mSlotAnimation.isRunning()) {
                updateSlotAnimationSpeed(percentage);
            } 
        } 
    } 
 
    private void updateSlotAnimationSpeed(float percentage) {
        // Adjust the duration and current play time of the rotation animation so that it's sped up or slowed 
        // down based on the sampling rate. 
        long duration = getRotationDuration(percentage);
        long currentPlayTime = mSlotAnimation.getCurrentPlayTime();
        long currentDuration = mSlotAnimation.getDuration();
        float currentPercentage = (float) currentPlayTime / currentDuration;
        long playTime = (long) (currentPercentage * duration);
        mSlotAnimation.setDuration(duration);
        mSlotAnimation.setCurrentPlayTime(playTime);
    } 
 
    private static long getRotationDuration(float percentage) {
        return (long) (MAX_ROTATION_DURATION - (ROTATION_DURATION * percentage));
    }