1

更新:残念ながら、私の質問に対する解決策はまだ得られません...

私はアンドロイドでレコーダーを開発しており、録音中に視覚化したいと思っています。私は以下のクラスを持っています。プロジェクトを実行して開始レコードを押すと、記録中にビジュアライザーが表示されません。実際のデバイスで次のコードをテストし、マニフェストにアクセス許可を追加します。

<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>

「Felix Palmer」による再生用のオープン ソース プロジェクト ビジュアライザーを使用し、ビジュアライザーにリンク レコーダーの新しいメソッドを独自に追加しました。私は完全に実行する必要があると思います.しかし、残念ながら私のレコーダーの実際の表示. (コードにエラーはありません) 問題を解決してビジュアライザーを表示するにはどうすればよいですか? これはVisualizerView.javaクラス...

import java.util.HashSet;
import java.util.Set;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.media.MediaPlayer;
import android.media.MediaRecorder;
import android.media.audiofx.Visualizer;
import android.util.AttributeSet;
import android.view.View;
import com.pheelicks.visualizer.renderer.Renderer;

public class VisualizerView extends View {

  private byte[] mBytes;
  private byte[] mFFTBytes;
  private Rect mRect = new Rect();
  private Visualizer mVisualizer;

  private Set<Renderer> mRenderers;

  private Paint mFlashPaint = new Paint();
  private Paint mFadePaint = new Paint();

  public VisualizerView(Context context, AttributeSet attrs, int defStyle)
  {
    super(context, attrs);
    init();
  }

  public VisualizerView(Context context, AttributeSet attrs)
  {
    this(context, attrs, 0);
  }

  public VisualizerView(Context context)
  {
    this(context, null, 0);
  }

  private void init() {
    mBytes = null;
    mFFTBytes = null;

    mFlashPaint.setColor(Color.argb(122, 255, 255, 255));
    mFadePaint.setColor(Color.argb(238, 255, 255, 255)); // Adjust alpha to change how quickly the image fades
    mFadePaint.setXfermode(new PorterDuffXfermode(Mode.MULTIPLY));

    mRenderers = new HashSet<Renderer>();
  }
//-----------------------------------------------
  public void link(MediaRecorder recorder)
  {
    if(recorder == null)
    {
      throw new NullPointerException("Cannot link to null MediaPlayer");
    }
    mVisualizer = new Visualizer(0);
    mVisualizer.setCaptureSize(Visualizer.getCaptureSizeRange()[1]);

    Visualizer.OnDataCaptureListener datacaptureListener1=new  Visualizer.OnDataCaptureListener() 
     {

        @Override
        public void onWaveFormDataCapture(Visualizer visualizer, byte[] bytes,
                int samplingRate) 
        {
            // TODO Auto-generated method stub
              updateVisualizer(bytes);
        }

        @Override
        public void onFftDataCapture(Visualizer visualizer, byte[] bytes,
                int samplingRate) 
        {
            // TODO Auto-generated method stub
            updateVisualizerFFT(bytes);
        }
    };
      mVisualizer.setDataCaptureListener(datacaptureListener1,Visualizer.getMaxCaptureRate() /2,false,true);
        mVisualizer.setEnabled(true);
  }

  //-----------------------------------------------

これはAudioRecorder.java...

public class AudioRecorder 
{
    private String name="";
    private static int id=0;
    private MediaRecorder recorder = new MediaRecorder();
    private String path=null;
   VisualizerView mVisualizerView;
   private Context context=null;
    //-----------------------------------------------   
     public AudioRecorder(Context context)
     {
         this.context=context;
     }

    //-----------------------------------------------        

     public void Record() throws IOException 
        {

            recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
            recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
            recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
            recorder.setOutputFile(this.path); 
            LayoutInflater inflater = LayoutInflater.from(context);
            View view = inflater.inflate(R.layout.recorder1, null);
            mVisualizerView = (VisualizerView)view.findViewById(R.id.visualizer1);
               mVisualizerView.link(recorder);
               addLineRenderer();
            try 
            {
               recorder.prepare();
            } 
            catch (IllegalStateException e) 
            {
                e.printStackTrace();
            } 
            catch (IOException e) 
            {
                e.printStackTrace();
            }
            try 
            {
                System.out.println("****");
                recorder.start();
            } 
            catch (Exception e) 
            {
            }

        }

        //------------------------------------------     

        public void stopRecord() throws IOException 
        {           
            recorder.stop();
            recorder.release();

        }

そして、これは私の XML のビジュアライザーです。

<LinearLayout
               android:layout_width="fill_parent"
               android:layout_height="fill_parent"
               android:layout_weight="1"
               android:background="@drawable/highlight_shared"
               android:orientation="vertical"
               android:paddingLeft="10dp"
               android:paddingRight="10dp"
               android:paddingTop="5dp" >

               <FrameLayout
                   android:layout_width="fill_parent"
                   android:layout_height="0dp"
                   android:layout_weight="1"
                   android:background="@drawable/corner_liner" >
                 <com.pheelicks.visualizer.VisualizerView
                    android:id="@+id/visualizer1"
                    android:layout_width="match_parent"
                    android:layout_height="fill_parent"/>
               </FrameLayout>
           </LinearLayout>
4

1 に答える 1

0

これは、さまざまな理由による特定の電話の問題です。 サポートされていないデバイスのリストについては、 https ://code.google.com/p/android/issues/detail?id=64423 https://github.com/felixpalmer/android-visualizer/issues/5 参照して ください。

于 2015-03-26T06:16:12.367 に答える