我看不到可视化,同时在Android录制语音(I can't see visualizer

2019-10-19 05:14发布

更新:我遗憾的是不能让我的问题的解决方案尚未...

我正在开发Android设备上记录,我要在录音显示形象化。 我有波纹管类。 当我运行的项目,然后按开始记录我不能看到,而真实设备recording.I测试娄代码的任何可视化和添加权限来体现。

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

我从开源项目可视化工具使用的“费利克斯·帕尔默”打和自己添加新的方法,链接记录仪可视化。 我想,一定要真正为我的录音机不幸的是运行perfectly.but任何表现。 (代码并没有任何错误),我该如何解决我的问题,看看可视化? 这是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>

Answer 1:

它与某些手机不同的原因的问题。 你可以在这里看到https://code.google.com/p/android/issues/detail?id=64423 https://github.com/felixpalmer/android-visualizer/issues/5对于不支持的设备列表中。



文章来源: I can't see visualizer while recording voice on Android