求高手改写一下代码,

andy_123 2012-04-05 12:48:52
下面的代码用到了 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();
}
}
...全文
130 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
追风筝的孩子 2012-04-05
  • 打赏
  • 举报
回复
可以直接用mediaplayer。。。不用自己一行行读
andy_123 2012-04-05
  • 打赏
  • 举报
回复
楼上:
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);
aSysBang 2012-04-05
  • 打赏
  • 举报
回复
具体 哪个类 哪个函数
上面涉及的函数不是很多吧

80,472

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧