在Android上录制语音时,我看不到可视化工具

时间:2014-01-07 09:33:35

标签: android visualizer recorder

更新:遗憾的是我无法解决我的问题......

我在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>

1 个答案:

答案 0 :(得分:0)

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