我在屏幕右侧有一个视图:
<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;
}
但这会改变音量太快。有没有办法像MXPlayer一样减慢音量变化?
答案 0 :(得分:1)
我找到了办法。没有完美的工作,但完成工作!
@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;
}