2016-05-16 140 views
1

我在屏幕的右側視圖:MXPlayer如音量控制

<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一樣減慢音量變化?

回答

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; 
    }