Android MX播放器式音量控制

Android MX播放器式音量控制,android,Android,我在屏幕右侧有一个视图: <View android:layout_width="match_parent" android:layout_height="fill_parent" android:layout_weight="1" android:id="@+id/right_scroll"> </View> 我已使用以下方法将滚动事件侦听器连接到它: @Override public boolean onScrol

我在屏幕右侧有一个视图:

<View
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:layout_weight="1"
    android:id="@+id/right_scroll">
</View>

我已使用以下方法将滚动事件侦听器连接到它:

    @Override
    public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
        AudioManager audioManager = (AudioManager) getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
        Log.d("Gesture ", " onScroll");
        if (e1.getY() < e2.getY()){
            audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_LOWER, AudioManager.FLAG_SHOW_UI);
        }
        if(e1.getY() > e2.getY()) {
            audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_RAISE, AudioManager.FLAG_SHOW_UI);
        }
        return false;
    }
@覆盖
公共布尔onScroll(MotionEvent e1、MotionEvent e2、浮点距离X、浮点距离Y){
AudioManager AudioManager=(AudioManager)getApplicationContext().getSystemService(Context.AUDIO_服务);
Log.d(“手势”、“onScroll”);
if(e1.getY()e2.getY()){
audioManager.setStreamVolume(audioManager.STREAM\u MUSIC、audioManager.ADJUST\u RAISE、audioManager.FLAG\u SHOW\u UI);
}
返回false;
}

但这改变了音量的方式太快了。有没有办法像MXPlayer那样降低音量的变化?

我找到了一种方法。虽然工作不完美,但完成了任务

    @Override
    public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
        if (e1.getY() < e2.getY() ){
            volumeUp = 0;
            volumeDown += 1;
            if(volumeDown > 7) {
                Log.i("Increased", "Vol decrease");
                audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_LOWER, AudioManager.FLAG_SHOW_UI);
                volumeDown = 0;
            }
        }
        if(e1.getY() > e2.getY()) {
            volumeDown = 0;
            volumeUp += 1;
            if(volumeUp > 7){
                Log.i("Increased", "Vol increase");
                audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_RAISE, AudioManager.FLAG_SHOW_UI);
                volumeUp = 0;
            }

        }
        return false;
    }
@覆盖
公共布尔onScroll(MotionEvent e1、MotionEvent e2、浮点距离X、浮点距离Y){
if(e1.getY()7){
对数i(“增加”、“体积减少”);
audioManager.adjustStreamVolume(audioManager.STREAM\u MUSIC、audioManager.Adjustu LOWER、audioManager.FLAG\u SHOW\u UI);
体积下降=0;
}
}
if(e1.getY()>e2.getY()){
体积下降=0;
体积p+=1;
如果(体积p>7){
对数i(“增加”、“体积增加”);
audioManager.adjustStreamVolume(audioManager.STREAM\u MUSIC、audioManager.ADJUST\u RAISE、audioManager.FLAG\u SHOW\u UI);
体积p=0;
}
}
返回false;
}