Results 1 to 2 of 2
  1. #1
    NARs is offline Member
    Join Date
    Oct 2009
    Posts
    5
    Rep Power
    0

    Default java.lang.Error: Error opening DSound for capture

    hi all.
    when i excuete the code , i got the error msg "java.lang.Error: Error opening DSound for capture" , how to solve the problem ?
    Java Code:
    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();
      }
    }

    Any help will be appreciated!

  2. #2
    literallyjer is offline Member
    Join Date
    Oct 2009
    Posts
    25
    Rep Power
    0

    Default

    Are you sure the device you are trying to capture from exists?

Similar Threads

  1. java.lang.NullPointerException Error
    By Manfizy in forum NetBeans
    Replies: 3
    Last Post: 02-24-2011, 06:27 AM
  2. Replies: 3
    Last Post: 01-26-2009, 05:30 PM
  3. How to over come java.lang.out of memory error
    By Chaitra_gm in forum New To Java
    Replies: 5
    Last Post: 09-28-2008, 10:33 AM
  4. Replies: 2
    Last Post: 09-18-2008, 07:30 AM
  5. Replies: 1
    Last Post: 07-31-2007, 11:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •