下面的代码用到了 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();
                }
            }

解决方案 »

  1.   

    楼上:
     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);
      

  2.   

    可以直接用mediaplayer不用自己一行行读