1

更新:不幸的是,我还无法为我的问题找到解决方案......

我正在android上开发一个记录器,我想在记录时显示可视化。我有以下课程。当我运行项目并按下开始记录时,我在录制时看不到任何可视化工具。我在真实设备上测试下面的代码并添加权限到清单。

<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 回答