package com.avcon.mic;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.sql.Connection;
import java.util.Vector;
import com.avcon.mic.AudioTool.MicRealTimeListener;
import com.avcon.mic.AudioTool.MicrophoneThread;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.media.AudioFormat;
import android.media.AudioRecord;
import android.media.MediaRecorder;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class MicDemoActivity extends Activity implements OnClickListener{
private TextView tView1,tView2;
private Button button1,button2,button3,button4;
private MHandler mHandler;
private MediaRecorder mARecorder;
private File mAudiofile,mSampleDir;
private MicrophoneThread microphone;
//private RecordThread recordThread;
private boolean istrue = true;
private static final String CONSER = "logInfo:";
private Runtime runtime = null;
private Process process = null;//服务器连接进程
private DataInputStream logInfoStream = null;
public StringBuffer stateInfoParser = null;
Process localProcess ;
class MHandler extends Handler{
@Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
super.handleMessage(msg);
switch (msg.what) {
case 1:
tView1.setText( msg.obj.toString());
break;
case 2:
tView2.setText("///////////////"+msg.obj.toString());
}
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
init();
mHandler = new MHandler();
microphone = new MicrophoneThread();
// recordThread = new RecordThread();
button1.setOnClickListener(this);
button2.setOnClickListener(this);
button3.setOnClickListener(this);
button4.setOnClickListener(this);
}
private void init(){
tView1 = (TextView) findViewById(R.id.textView1);
tView2 = (TextView) findViewById(R.id.textView2);
button1 = (Button) findViewById(R.id.button1);
button2 = (Button) findViewById(R.id.button2);
button3 = (Button) findViewById(R.id.button3);
button4 = (Button) findViewById(R.id.button4);
}
@Override
public void onClick(View v) {
// 在代码中运行linux命令
switch (v.getId()) {
case R.id.button1:
Log.v("ClientField.LOG_TAG "," LogTagField.THREAD_CON "+ "进入连接线程!");
runtime = Runtime.getRuntime();
try
{
process = runtime.exec("ls /system/bin/");
if (process != null)
{
try
{
Object localObject = process.getOutputStream();
Object intputObject = process.getInputStream();
Object errorObject = process.getErrorStream();
DataOutputStream localDataOutputStream = new DataOutputStream((OutputStream)localObject);
localDataOutputStream.flush();
Log.v("ClientField.LOG_TAG" ,"LogTagField.THREAD_CON" + "执行连接命令");
logInfoStream = new DataInputStream((InputStream)intputObject);
DataInputStream erroStream = new DataInputStream((InputStream) errorObject);
String lineInfo = "";
stateInfoParser = new StringBuffer();
while ((lineInfo = logInfoStream.readLine()) != null)
{
stateInfoParser.append(lineInfo);
stateInfoParser.append("\n");
Log.v("MicDemoActivity" , "stateInfoParser.append ls "+ stateInfoParser.toString());
}
Log.v("MicDemoActivity" , "LogTagField.THREAD_CON "+ "跳出连接线程!");
String lineInfo1 = "";
// localDataOutputStream.writeBytes("/sdcard/ls /sdcard");
// localDataOutputStream.flush();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
process = runtime.exec("ls");
if (process != null)
{
process.waitFor();
}
//tView1.setText(stateInfoParser.toString());
}else
{
Log.e("ClientField.LOG_TAG" ,"LogTagField.THREAD_CON" + "process is null");
}
}catch (Exception e) {
e.printStackTrace();
Log.e("ClientField.LOG_TAG "," LogTagField.THREAD_CON" + "runtim error");
process = null;
}
tView1.setText(stateInfoParser.toString());
break;
case R.id.button2:
Toast.makeText(MicDemoActivity.this, "录音结束", Toast.LENGTH_LONG).show();
button1.setEnabled(true);
mARecorder.stop();
istrue = false;
microphone.stop();
mARecorder.release();
mARecorder = null;
break;
// case R.id.button3:
/**跳转至本机安装的超级终端*/
// ComponentName componentName=new
// ComponentName("com.magicandroidapps.bettertermpro","com.magicandroidapps.bettertermpro.BetterTerm");
// Intent intent=new Intent();
// intent.setComponent(componentName);
// intent.setAction(Intent.ACTION_VIEW);
// startActivity(intent);
//
// break;
case R.id.button4:
Vector localVector = new Vector();
try
{
localProcess = Runtime.getRuntime().exec("su ");
Log.e("MicDemoActivity", "第一命令");
OutputStream localOutputStream = localProcess.getOutputStream();
DataOutputStream localDataOutputStream = new DataOutputStream(localOutputStream);
InputStream localInputStream = localProcess.getInputStream();
DataInputStream localDataInputStream = new DataInputStream(localInputStream);
String str1 = String.valueOf("ls");
String str2 = str1 + "\n";
localDataOutputStream.writeBytes(str2);
Log.e("MicDemoActivity", "第er命令");
localProcess = Runtime.getRuntime().exec(str2);
localOutputStream = localProcess.getOutputStream();
localInputStream = localProcess.getInputStream();
localDataInputStream = new DataInputStream(localInputStream);
System.out.println("111"+localDataInputStream.readLine());
localDataOutputStream.flush();
localDataOutputStream.writeBytes("exit");
Log.e("MicDemoActivity", "第三命令");
localOutputStream = localProcess.getOutputStream();
localInputStream = localProcess.getInputStream();
localDataInputStream = new DataInputStream(localInputStream);
System.out.println("222"+localDataInputStream.readLine());
localDataOutputStream.flush();
String str3 = localDataInputStream.readLine();
localVector.add(str3);
localProcess.waitFor();
// tView1.setText(localVector.toString());
}
catch (Exception localException)
{
localException.printStackTrace();
}
break;
}
}
@Override
protected void onStart() {
// 录音获取麦克风声音
super.onStart();
Toast.makeText(MicDemoActivity.this, "录音开始", Toast.LENGTH_LONG).show();
button1.setEnabled(false);
mARecorder = new MediaRecorder();
mARecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mARecorder.setOutputFormat(MediaRecorder.OutputFormat.RAW_AMR);
mARecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
try {
mSampleDir = Environment.getExternalStorageDirectory();
mAudiofile = File.createTempFile(
没有合适的资源?快使用搜索试试~ 我知道了~
android实时获取麦克风声音
共41个文件
class:18个
png:6个
xml:6个
4星 · 超过85%的资源 需积分: 50 195 下载量 146 浏览量
2015-04-05
22:45:38
上传
评论 6
收藏 103KB ZIP 举报
温馨提示
实时获取麦克风输入,可用来开发手机助听器等
资源推荐
资源详情
资源评论
收起资源包目录
实时获取麦克风声音.zip (41个子文件)
实时获取麦克风声音
MicDemo
AndroidManifest.xml 2KB
res
layout
emulator1.xml 461B
main.xml 2KB
emulator.xml 419B
drawable-ldpi
ic_launcher.png 2KB
drawable-mdpi
ic_launcher.png 3KB
drawable-hdpi
ic_launcher.png 4KB
values
strings.xml 180B
attrs.xml 257B
proguard.cfg 1KB
src
com
avcon
mic
MicDemoActivity.java 16KB
FileUtil.java 118B
AudioTool.java 12KB
bin
classes
com
avcon
mic
AudioTool$1.class 997B
MicDemoActivity$MHandler.class 1KB
AudioTool$MicRealTimeListener.class 251B
R$styleable.class 539B
AudioTool$MicrophoneThread.class 2KB
AudioTool$SecondCounter.class 1KB
R.class 547B
R$layout.class 444B
R$attr.class 387B
MicDemoActivity$MicrophoneThread.class 2KB
R$id.class 696B
R$string.class 412B
AudioTool$2.class 771B
AudioTool.class 9KB
MicDemoActivity.class 12KB
AudioTool$3.class 1KB
R$drawable.class 392B
FileUtil.class 277B
MicDemo.apk 25KB
res
drawable-ldpi
ic_launcher.png 2KB
drawable-mdpi
ic_launcher.png 2KB
drawable-hdpi
ic_launcher.png 4KB
classes.dex 23KB
resources.ap_ 13KB
.classpath 364B
assets
project.properties 360B
.project 843B
gen
com
avcon
mic
R.java 3KB
共 41 条
- 1
commandlife2
- 粉丝: 3
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页