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 269 下载量 192 浏览量
2013-03-27
10:14:48
上传
评论 4
收藏 99KB RAR 举报
温馨提示
可以实现微信QQ发送语音那种实时音量的捕获
资源推荐
资源详情
资源评论
收起资源包目录
实时获取麦克风声音.rar (41个子文件)
实时获取麦克风声音
MicDemo
bin
classes.dex 23KB
res
drawable-ldpi
ic_launcher.png 2KB
drawable-hdpi
ic_launcher.png 4KB
drawable-mdpi
ic_launcher.png 2KB
classes
com
avcon
mic
AudioTool$2.class 771B
R$layout.class 444B
MicDemoActivity$MHandler.class 1KB
FileUtil.class 277B
R$id.class 696B
R$drawable.class 392B
R$attr.class 387B
R.class 547B
AudioTool$3.class 1KB
R$styleable.class 539B
AudioTool$MicrophoneThread.class 2KB
AudioTool$MicRealTimeListener.class 251B
AudioTool$SecondCounter.class 1KB
R$string.class 412B
MicDemoActivity$MicrophoneThread.class 2KB
MicDemoActivity.class 12KB
AudioTool.class 9KB
AudioTool$1.class 997B
resources.ap_ 13KB
MicDemo.apk 25KB
res
drawable-ldpi
ic_launcher.png 2KB
drawable-hdpi
ic_launcher.png 4KB
values
strings.xml 180B
attrs.xml 257B
drawable-mdpi
ic_launcher.png 3KB
layout
emulator1.xml 461B
main.xml 2KB
emulator.xml 419B
assets
gen
com
avcon
mic
R.java 3KB
proguard.cfg 1KB
src
com
avcon
mic
AudioTool.java 12KB
FileUtil.java 118B
MicDemoActivity.java 16KB
.project 843B
.classpath 364B
project.properties 360B
AndroidManifest.xml 2KB
共 41 条
- 1
蜗牛
- 粉丝: 32
- 资源: 16
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
- 6
前往页