0
更新:我很遺憾不能得到一個解決方案,我的問題......我無法看到可視化,同時在Android錄製語音
我開發在Android的記錄,我想展示形象化的同時錄製。我有下課。 當我運行項目並按下開始記錄時,我無法在記錄時看到任何可視化器。我在真實設備上測試了波紋管代碼並添加了清單的權限。
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
我從開源項目可視化工具使用的「費利克斯·帕爾默」打和自己的聯繫記錄添加新的方法來可視化。我認爲必須完美運行,但不幸的是,我的錄音機真的顯示。 (代碼沒有任何錯誤) 我如何解決我的問題,並看到可視化? 這是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>
請參閱https://github.com/steelkiwi/AndroidRecording,我希望能夠幫助您 –
您正在初始化Vizualizer與0,輸出混合。您應該使用錄像機的音頻會話進行初始化。 – Tenfour04
@ Tenfour04但在2.3.3版本不支持此方法。我不希望更改版本更高。那麼怎麼辦呢? – sarah