3

サウンドメーターを作成するためにマイクレベルを取得する必要があるアプリを書いています。私はこれを見つけました: Android Media Player Decibel Reading。100% の種類の取引のうち、現在のレベルを表示するメーターを作成する必要があります。たとえば、バーが高くなるほど赤くなります。レベルを表示するためのコードを取得するだけでも素晴らしいです。

上記のリンクには、現在のデシベルの読み取り値を取得する方法がありますが、別のスレッドで実行して常に更新する必要があるようです。VU メーターを読み取っていましたが、どこから始めればよいかわかりません。

前もって感謝します!

4

1 に答える 1

4

さて、あなたがあなたの質問でリンクしたコードであなたが働いていると仮定しています。

したがって、このメーターは、振幅の値に応じて、その場でサイズと色を変更する必要があります。

形状を描画するには、以下に示すように、Viewクラスを拡張し、onDrawメソッドをオーバーライドします。

float x,y; //CONSTANTS FOR WHERE YOU WANT YOUR BAR TO BE
float baseWidth; // This is the width of one block. 
                 //Number of blocks together will be your rectangle
float nwidth;     //This is the number of blocks varying according to amplitude
float height;    //CONSTANT HEIGHT
Paint color=new Paint();     

//For drawing meter
public void onDraw(Canvas c){
  changeColorAndSize();
  Rect rect = new Rect(x, y, x + (baseWidth*nwidth), y + height);
  shapeDrawable.setBounds(rect);
  shapeDrawable.getPaint().set(paint);
  shapeDrawable.draw(canvas);

}

public void changeColorAndSize(){
       double amp=getAmplitude();
       nWidth=amp;
       paint.setARGB (a, r*(Integer.parseInt(amp)), g, b);
      //This will change the redness of the bar. a,g and b will have to be set by you

}

public double getAmplitude() {
        if (mRecorder != null)
                return  (mRecorder.getMaxAmplitude());
        else
                return 0;
}

'x'秒ごとにメーターを変更するには、postInvalidate()繰り返し呼び出す必要があります

また

アニメーションを使用しstartAnimation()て、ビューから呼び出します。

于 2012-12-06T06:24:29.683 に答える