Code example for ObjectAnimator

Methods: getCurrentPlayTime, getDuration, isRunning, setCurrentPlayTime, setDuration, start

0
            Toast.makeText(getActivity(), "Unable to play this file.  Please try again", Toast.LENGTH_SHORT).show();
        } 
    } 
 
    private void startSlotAnimation() { 
        if (!mSlotAnimation.isRunning()) {
            float rotation = mControlView.getTrackSlotView().getRotation();
            long playTime = (long) ((rotation / 360) * mSlotAnimation.getDuration());
            mSlotAnimation.start();
            mSlotAnimation.setCurrentPlayTime(playTime);
            updateSlotAnimationSpeed(mSamplingRateValue);
        } 
    } 
 
    @Override 
    public void onClick(View v) {
        if (v.getId() == R.id.TrackSlotView) {
            if (mAudioEngine != null) {
                if (mAudioEngine.isPlaying()) {
                    stopEngine(); 
                } else { 
                    startEngine(); 
                } 
            } 
        } else if (v.getId() == R.id.GainOption) {
            setMode(MODE_GAIN);
            mPopupWindow.dismissPopup();
        } else if (v.getId() == R.id.SampleRateOption) {
            setMode(MODE_SAMPLE_RATE);
            mPopupWindow.dismissPopup();
        } 
    } 
 
    private void stopEngine() { 
        mAudioEngine.stop();
        stopSlotAnimation(); 
    } 
 
    private class ImageLoadThread extends Thread {
 
        private long mAlbumId;
        private Context mContext;
        private Handler mHandler;
        private ImageView mImageView;
 
        public ImageLoadThread(Context context, ImageView imageView, long albumId) {
            mContext = context;
            mImageView = imageView;
            mAlbumId = albumId;
            mHandler = new Handler();
        } 
 
        @Override 
        public void run() { 
            try { 
                final Bitmap bitmap = new AlbumArtProvider().getCircularAlbumArtwork(mContext, mAlbumId);
                mHandler.post(new Runnable() {
 
                    @Override 
                    public void run() { 
                        mImageView.setImageBitmap(bitmap);
                    } 
                }); 
            } catch (FileNotFoundException e) {
                // Ignore image load fails 
            } 
        } 
 
    } 
 
    @Override 
    public void onProgressChanged(VerticalSeekBar seekBar, int progress) {
        float percentage = (float) progress / seekBar.getMax();
        if (mMode == MODE_GAIN) {
            setGain(percentage);
        } else if (mMode == MODE_SAMPLE_RATE) {
            setSamplingRate(percentage);
        } 
    } 
 
    private void setGain(float percentage) {
        mGainValue = percentage;
 
        if (mAudioEngine != null) {
            if (mGainProcessor == null) {
                mGainProcessor = new GainProcessor();
                mAudioEngine.addProcessor(mGainProcessor);
            } 
            mGainProcessor.setGain(mGainValue);
        } 
    } 
 
    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));
    }