andy_123 2012年04月05日
求高手改写一下代码,
下面的代码用到了 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();
}
}
...全文
77 点赞 收藏 3
写回复
3 条回复

还没有回复,快来抢沙发~

发动态
发帖子
Android
创建于2009-10-09

4.6w+

社区成员

9.0w+

社区内容

移动平台 Android
社区公告
暂无公告