下面的代码用到了 javax.sound.sampled,有没有办法不使用javax.sound.sampled,直接用android sdk支持的包改写呢? public void run()
{
final AudioFormat audioFormat = new AudioFormat(8000f /*sample rate*/,
16 /*sample size in bits*/, 1 /*channels*/, true /*signed*/, true /*big endian*/);
final DataLine.Info dataLineInfo = new DataLine.Info(TargetDataLine.class, audioFormat);
try
{
final TargetDataLine targetDataLine = (TargetDataLine) AudioSystem.getLine(dataLineInfo);
// opens line if necessary
if (!targetDataLine.isOpen())
{
targetDataLine.open();
}
// starts data line
targetDataLine.start();
Thread capture = new Thread(new Runnable()
{
public void run()
{
while (!stopped)
{
byte[] buf = new byte[512];
int offset = 0;
while (offset < buf.length)
{
offset += targetDataLine.read(buf, offset, buf.length - offset);
}
encode(buf);
}
}
});
capture.start();
while (!stopped)
{
try
{
Thread.sleep(1 * 1000);
}
catch (Exception e) {/*ignore*/}
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
{
final AudioFormat audioFormat = new AudioFormat(8000f /*sample rate*/,
16 /*sample size in bits*/, 1 /*channels*/, true /*signed*/, true /*big endian*/);
final DataLine.Info dataLineInfo = new DataLine.Info(TargetDataLine.class, audioFormat);
try
{
final TargetDataLine targetDataLine = (TargetDataLine) AudioSystem.getLine(dataLineInfo);
// opens line if necessary
if (!targetDataLine.isOpen())
{
targetDataLine.open();
}
// starts data line
targetDataLine.start();
Thread capture = new Thread(new Runnable()
{
public void run()
{
while (!stopped)
{
byte[] buf = new byte[512];
int offset = 0;
while (offset < buf.length)
{
offset += targetDataLine.read(buf, offset, buf.length - offset);
}
encode(buf);
}
}
});
capture.start();
while (!stopped)
{
try
{
Thread.sleep(1 * 1000);
}
catch (Exception e) {/*ignore*/}
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
解决方案 »
- android 使用BASE64Decoder and BASE64Encoder
- android4.0, 应用程序显示方式(launcher上显示)调整问题
- linux的eclipse开发android没法用手机运行
- Android视频通话
- 来电时accelerometerlistener被停用
- 利用Notification显示消息的问题
- 运行AVD的时候,当点start后不能得到虚拟手机界面
- 新版adt里的fragment_main.xml
- 怎么不显示界面了自定义内部类baseadapter实现gridview从R文件取id
- 在Android Studio中,怎么把按钮放在底部位置,且不随上面的文本移动
- 关于Intent-Filter的一点问题
- 关于android 数据的重复使用
final AudioFormat audioFormat = new AudioFormat(8000f /*sample rate*/,
16 /*sample size in bits*/, 1 /*channels*/, true /*signed*/, true /*big endian*/);
final DataLine.Info dataLineInfo = new DataLine.Info(TargetDataLine.class, audioFormat);