简体   繁体   中英

Using a webcam in a java application

I am using netbeans IDE 7.1.1 I'm making the application capture an image from a webcam, but my problem is that when I run that application first time it gives me proper output but when I run the same application again, it gives me this error:

java.io.IOException: Could not connect to capture device
javax.media.NoDataSourceException: Error instantiating class: com.sun.media.protocol.vfw.DataSource : java.io.IOException: Could not connect to capture device
    at javax.media.Manager.createDataSource(Manager.java:1012)

can anyone tell me why this is happening?

my code is:

             /* Grab the default web cam*/
             MediaLocator ml = new MediaLocator("vfw://0");

        /* Create my data source */
        DataSource ds = Manager.createDataSource(ml);

        requestFormatResolution(ds);

        /* Create & start my player */
        Player p = Manager.createRealizedPlayer(ds);

        p.start();
            Component videoScreen = p.getVisualComponent();

You need to close your Player and deallocate it as well.

Simply do the following:

player.close();
player.deallocate();

For more details of these methods, look at the API ( close() and deallocate() ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM