作者 主題: java.lang.Error: Error opening DSound for capture  (閱讀 4518 次)

0 會員 與 1 訪客 正在閱讀本文。

NARs

  • 活潑的大學生
  • ***
  • 文章數: 227
    • 檢視個人資料
各位高手~
為什麼在執行下列程式,會有java.lang.Error: Error opening DSound for capture 錯誤?

代碼: [選擇]
import javax.media.CaptureDeviceManager;
import javax.media.CaptureDeviceInfo;
import javax.media.DataSink;
import javax.media.Manager;
import javax.media.MediaLocator;
import javax.media.NoProcessorException;
import javax.media.NotRealizedError;
import javax.media.Processor;
import javax.media.format.AudioFormat;
import javax.media.rtp.*;
import javax.media.protocol.ContentDescriptor;
import javax.media.protocol.DataSource;
import javax.media.control.FormatControl;
import javax.media.control.TrackControl;
 
import java.util.Vector;
import java.io.*;
 
public class sendMedia extends Thread {
  CaptureDeviceInfo di = null;
  float fFrameRate = 44100.0F;
  Processor p = null;
  DataSink d;
 
  public sendMedia(String url) {
    //Get the CaptureDeviceInfo for the live audio capture device
    Vector deviceList = CaptureDeviceManager.getDeviceList(new AudioFormat("linear",
                                                                           44100,
                                                                           16,
                                                                           2));
    if (deviceList.size() > 0)
      di = (CaptureDeviceInfo)deviceList.firstElement();
    else {
      System.exit(-1);
    }
 
    try {
      p = Manager.createProcessor(di.getLocator());
    } catch (IOException e) {
      System.exit(-1);
    } catch (NoProcessorException e) {
      System.exit(-1);
    }
 
    int ProcessStatus;
    p.configure();
 
    while(p.getState() == 140) {}
 
    p.setContentDescriptor(new ContentDescriptor(ContentDescriptor.RAW));
    TrackControl track[] = p.getTrackControls();
    boolean encodingOk = false;
    //Go through the tracks and try to program one of them to
    //output gsm data.
    for (int i = 0; i < track.length; i++) {
      if (!encodingOk && track[i] instanceof FormatControl) { 
        if (((FormatControl)track[i]).setFormat(
                  new AudioFormat(AudioFormat.GSM_RTP,  8000, 8, 1)) == null) {
          track[i].setEnabled(false);
        }
        else {
          encodingOk = true;
        }
      } else {
      //we could not set this track to gsm, so disable it
      track[i].setEnabled(false);
      }
    }
    //At this point, we have determined where we can send out
    //gsm data or not.
    //realize the processor
    if (encodingOk) {
      p.realize();
      while(p.getState() ==200) {}
    //get the output datasource of the processor and exit
    //if we fail
      DataSource ds = null;
      try {
        ds = p.getDataOutput();
      } catch (NotRealizedError e) {
        System.exit(-1);
      }
      //hand this datasource to manager for creating an RTP
      //datasink our RTP datasimnk will multicast the audio
      try {
        String srcFile = "/C:/tmp/test.wav";

     //   MediaLocator m = new MediaLocator(url);
        MediaLocator m =  new MediaLocator("file:" + srcFile);
        d = Manager.createDataSink(ds, m);
      } catch (Exception e) {
        System.exit(-1);
      }
    }
  }
 
  public void run() {
    try {
      p.start();
      d.open();
      d.start();
    } catch (Exception e) {
      System.exit(-1);
    }     
  }
 
  public static void main(String args[]) {
   // sendMedia send = new sendMedia(args[0]);  //ex:rtp://192.168.1.2:3000/audio/1
    String str = "rtp://192.168.1.2:3000/audio/";
    sendMedia send = new sendMedia(str);  //ex:rtp://192.168.1.2:3000/audio/1
    Thread startSend = new Thread(send);
    startSend.start();
  }
}