我看不到可视化,同时在Android语音录制 [英] I can't see visualizer while recording voice on Android
问题描述
更新:我遗憾的是不能让我的问题的解决方案尚未...
我开发android上的记录,我想节目的同时录制可视化。我有波纹管类。
当我运行项目和preSS开始记录我看不到真实的设备,同时recording.I测试波纹管code的可视化,并添加权限来体现。
<使用许可权的android:NAME =android.permission.RECORD_AUDIO/>
<使用许可权的android:NAME =android.permission.MODIFY_AUDIO_SETTINGS/>
我从开源项目使用的可视化由费利克斯·帕尔默打和自己的联系记录添加新的方法来可视化。我认为,必须真正为我的录音机不幸的是运行perfectly.but任何表现。 (code也没有任何错误)
我怎样才能解决我的问题,看看可视化?
这是 VisualizerView.java
类...
进口java.util.HashSet中;
进口java.util.Set中;进口android.content.Context;
进口android.graphics.Bitmap;
进口android.graphics.Bitmap.Config;
进口android.graphics.Canvas;
进口android.graphics.Color;
进口android.graphics.Matrix;
进口android.graphics.Paint;
进口android.graphics.PorterDuff.Mode;
进口android.graphics.PorterDuffXfermode;
进口android.graphics.Rect;
进口android.media.MediaPlayer;
进口android.media.MediaRecorder;
进口android.media.audiofx.Visualizer;
进口android.util.AttributeSet;
进口android.view.View;
进口com.pheelicks.visualizer.renderer.Renderer;公共类VisualizerView扩展视图{ 私人字节[]字节;
私人字节[] mFFTBytes;
私人矩形mRect =新的矩形();
私人展示台mVisualizer; 私人设置<&渲染GT; mRenderers; 私人油漆mFlashPaint =新的油漆();
私人油漆mFadePaint =新的油漆(); 公共VisualizerView(上下文的背景下,ATTRS的AttributeSet,INT defStyle)
{
超(背景下,ATTRS);
在里面();
} 公共VisualizerView(上下文的背景下,ATTRS的AttributeSet)
{
这(背景下,ATTRS,0);
} 公共VisualizerView(上下文的背景下)
{
这(背景下,NULL,0);
} 私人无效的init(){
兆字节= NULL;
mFFTBytes = NULL; mFlashPaint.setColor(Color.argb(122,255,255,255));
mFadePaint.setColor(Color.argb(238,255,255,255)); //调整阿尔法改变图像褪色的速度有多快
mFadePaint.setXfermode(新PorterDuffXfermode(Mode.MULTIPLY)); mRenderers =新的HashSet<&渲染GT;();
}
// -----------------------------------------------
公共无效链接(MediaRecorder录像机)
{
如果(录像机== NULL)
{
抛出新的NullPointerException异常(无法链接到空的MediaPlayer);
}
mVisualizer =新的可视化工具(0);
mVisualizer.setCaptureSize(Visualizer.getCaptureSizeRange()[1]); Visualizer.OnDataCaptureListener datacaptureListener1 =新Visualizer.OnDataCaptureListener()
{ @覆盖
公共无效onWaveFormDataCapture(可视化可视化工具,字节[]字节,
INT采样速率)
{
// TODO自动生成方法存根
updateVisualizer(字节);
} @覆盖
公共无效onFftDataCapture(可视化可视化工具,字节[]字节,
INT采样速率)
{
// TODO自动生成方法存根
updateVisualizerFFT(字节);
}
};
mVisualizer.setDataCaptureListener(datacaptureListener1,Visualizer.getMaxCaptureRate()/ 2,假的,真正的);
mVisualizer.setEnabled(真);
} // -----------------------------------------------
这是 AudioRecorder.java
...
公共类AudioRecorder
{
私人字符串名称=;
私有静态诠释的id = 0;
私人MediaRecorder记录=新MediaRecorder();
私人字符串路径= NULL;
VisualizerView mVisualizerView;
私人上下文的背景下= NULL;
// -----------------------------------------------
公共AudioRecorder(上下文的背景下)
{
this.context =背景;
} // ----------------------------------------------- 公共无效记录()抛出IOException异常
{ recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEn codeR(MediaRecorder.AudioEn coder.AMR_NB);
recorder.setOutputFile(this.path);
LayoutInflater吹气= LayoutInflater.from(背景);
查看查看= inflater.inflate(R.layout.recorder1,NULL);
mVisualizerView =(VisualizerView)view.findViewById(R.id.visualizer1);
mVisualizerView.link(录像机);
addLineRenderer();
尝试
{
。录音机prepare();
}
赶上(IllegalStateException异常E)
{
e.printStackTrace();
}
赶上(IOException异常E)
{
e.printStackTrace();
}
尝试
{
的System.out.println(****);
recorder.start();
}
赶上(例外五)
{
} } // ------------------------------------------ 公共无效STO precord()抛出IOException异常
{
recorder.stop();
recorder.release(); }
这是在我的XML可视化工具。
<的LinearLayout
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:layout_weight =1
机器人:背景=@绘制/ highlight_shared
机器人:方向=垂直
机器人:paddingLeft =10dp
机器人:paddingRight =10dp
机器人:paddingTop =5DP> <的FrameLayout
机器人:layout_width =FILL_PARENT
机器人:layout_height =0dp
机器人:layout_weight =1
机器人:背景=@绘制/ corner_liner>
< com.pheelicks.visualizer.VisualizerView
机器人:ID =@ + ID / visualizer1
机器人:layout_width =match_parent
机器人:layout_height =FILL_PARENT/>
< /&的FrameLayout GT;
< / LinearLayout中>
这是某些手机不同的原因的问题。你可以在这里看到
的https://$c$c.google.com/p /安卓/问题/细节?ID = 64423
https://github.com/felixpalmer/android-visualizer/issues/5
不支持的设备列表。
Update : I unfortunately can't get a solution for my question yet...
I am developing a recorder on android and I want show visualize while recording. I have bellow classes. When I run project and press start record I cant see any visualizer while recording.I test bellow code on real device and add permissions to manifest.
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
I use from open source project visualizer for playing by "Felix Palmer" and own add new method for link recorder to visualizer. I think must be run perfectly.but really any showing for my recorder unfortunately. (code has not any error)
How i can resolve my problem and see visualizer?
This is VisualizerView.java
class...
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);
}
//-----------------------------------------------
This is 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();
}
And this is visualizer in my 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>
It is the issue with certain phones for different reasons. You can see here https://code.google.com/p/android/issues/detail?id=64423 https://github.com/felixpalmer/android-visualizer/issues/5 for the list of unsupported devices.
这篇关于我看不到可视化,同时在Android语音录制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!