求高手改写一下代码,

andy_123 andy_123 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
下面的代码用到了 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();
}
}
...全文
评论 3
收藏 已收藏
分享
返回顶部
andy_123
Android 80,489 成员 91,375 内容