首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在FMJ中没有发现捕获设备

在FMJ中没有发现捕获设备
EN

Stack Overflow用户
提问于 2012-04-12 11:09:14
回答 1查看 1.8K关注 0票数 2

以前我使用JMF,但是JMF需要安装,但我不想增加这种开销。所以我才想被调到FMJ。而FMJ是开源的。:)

在FMJ源程序中给出了一些示例。还有一个FMJStudio,在那里我可以运行和传输从麦克风捕捉到的RTP音频。

但是当我想传输RTP时,使用下面的源,它找不到任何捕获设备。

完整的源代码可以在以下网站上找到:fmj-20070928-0938_2.zip (在FMJ中),这个源类的类名是SimpleVoiceTransmiter.。

代码语言:javascript
复制
    //final String urlStr = URLUtils.createUrlStr(new File("samplemedia/gulp2.wav"));//"file://samplemedia/gulp2.wav";
    Format format;

    format = new AudioFormat(AudioFormat.ULAW_RTP, 8000, 8, 1);
    //format = new AudioFormat(AudioFormat.ULAW_RTP, 8000.0, 8, 1, AudioFormat.LITTLE_ENDIAN, AudioFormat.SIGNED);
    //format = new AudioFormat(BonusAudioFormatEncodings.ALAW_RTP, 8000, 8, 1);
    //format = new AudioFormat(BonusAudioFormatEncodings.SPEEX_RTP, 8000, 8, 1, -1, AudioFormat.SIGNED);
    //format = new AudioFormat(BonusAudioFormatEncodings.ILBC_RTP, 8000.0, 16, 1, AudioFormat.LITTLE_ENDIAN, AudioFormat.SIGNED);

    CaptureDeviceInfo di = null;
            //Set to true if you want to transmit audio from capture device, like microphone.
    if (true)
    {
        // First find a capture device that will capture linear audio
        // data at 8bit 8Khz
        AudioFormat captureFormat = new AudioFormat(AudioFormat.LINEAR, 8000, 8, 1);

        Vector devices = CaptureDeviceManager.getDeviceList(captureFormat);



        if (devices.size() > 0)
        {
            di = (CaptureDeviceInfo) devices.elementAt(0);
        } else
        {
            System.err.println("No capture devices");
            // exit if we could not find the relevant capturedevice.
            System.exit(-1);

        }
    }

    // Create a processor for this capturedevice & exit if we
    // cannot create it
    Processor processor = null;
    try
    {
        //processor = Manager.createProcessor(new MediaLocator(urlStr));
                    processor = Manager.createProcessor(di.getLocator());
    } catch (IOException e)
    {
        e.printStackTrace();
        System.exit(-1);
    } catch (NoProcessorException e)
    {
        e.printStackTrace();
        System.exit(-1);
    }

    // configure the processor
    processor.configure();

    while (processor.getState() != Processor.Configured)
    {
        try
        {
            Thread.sleep(10);
        } catch (InterruptedException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    processor.setContentDescriptor(new ContentDescriptor(ContentDescriptor.RAW_RTP));

    TrackControl track[] = processor.getTrackControls();

    boolean encodingOk = false;

    // Go through the tracks and try to program one of them to
    // output g.711 data.

    for (int i = 0; i < track.length; i++)
    {
        if (!encodingOk && track[i] instanceof FormatControl)
        {
            if (((FormatControl) track[i]).setFormat(format) == null)
            {

                track[i].setEnabled(false);
            } else
            {
                encodingOk = true;
            }
        } else
        {
            // we could not set this track to g.711, so disable it
            track[i].setEnabled(false);
        }
    }

    // At this point, we have determined where we can send out
    // g.711 data or not.
    // realize the processor
    if (encodingOk)
    {
        if (!new net.sf.fmj.ejmf.toolkit.util.StateWaiter(processor).blockingRealize())
        {
            System.err.println("Failed to realize");
            return;
        }

        // get the output datasource of the processor and exit
        // if we fail
        DataSource ds = null;

        try
        {
            ds = processor.getDataOutput();
        } catch (NotRealizedError e)
        {
            e.printStackTrace();
            System.exit(-1);
        }

        // hand this datasource to manager for creating an RTP
        // datasink our RTP datasink will multicast the audio
        try
        {
            String url = "rtp://192.168.1.99:49150/audio/1";

            MediaLocator m = new MediaLocator(url);

            DataSink d = Manager.createDataSink(ds, m);
            d.open();
            d.start();

            System.out.println("Starting processor");
            processor.start();
            Thread.sleep(30000);
        } catch (Exception e)
        {
            e.printStackTrace();
            System.exit(-1);
        }
    }

当我运行这个源时,输出是:没有捕获设备

有什么问题吗?

编辑:我从我的系统中卸载了JMF

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-04-13 18:54:02

好的,两天半后,我自己指出了这个问题。

问题是,当我卸载JMF时,它没有从CLASSPATH用户变量中删除。就像:

代码语言:javascript
复制
  "C:\PROGRA~1\JMF21~1.1E\lib\sound.jar;C:\PROGRA~1\JMF21~1.1E\lib\jmf.jar;C:\PROGRA~1\JMF21~1.1E\lib;"

当我移除它们,重新启动我的电脑。然后是宾果。代码运行时没有任何问题。:)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10122347

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档