web cam code

Hello experts,
I have this bit of code that i found here:

http://java.sun.com/dev/evangcentral/totallytech/jmf.html

I would like to use it to try to learn how to use a web cam within my site..
thanks.
kephillipsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

zzynxSoftware engineerCommented:
What's the question
0
kephillipsAuthor Commented:
oh sorry. How do I get this piece of code to work.
What type of file do I create, what do I need to add at the beginning and end of the code etc...
Thanks.
0
zzynxSoftware engineerCommented:
Did you download the zip file mentioned in the article?
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

kephillipsAuthor Commented:
yes, and it's just three files:

FrameGrabber.java
FrameGrabberExceptions.java
video.properties
 
I've tried running them and nothing....
0
zzynxSoftware engineerCommented:
>> I've tried running them and nothing....
What errors/messages?
0
zzynxSoftware engineerCommented:
And as you can read on that page:
"In addition to the standard Java Development Kit (JDK), a separate, platform-specific performance pack is required for the JMF API."
Did you installed that one?
0
zzynxSoftware engineerCommented:
0
kephillipsAuthor Commented:
yes i have looked at those places but can't seem to find anything for mac os X
0
kephillipsAuthor Commented:
ok. it seems i have updated my java (downloaded from apple). Now it still doesn't do anything.
NO errors...just nothing...
0
kephillipsAuthor Commented:
ok.
experts, I have a bit of code that I would like to test out. How do I embed this into a web page?????
THanks



public void printRGBDevices() {

   /*  Create a new default RGB format object (see the JMF documentation

    *  for other supported formats)

    */

   RGBformat rgbFormat = new RGBFormat();

 

   /*  Use the Format object to retrieve a Vector of CaptureDeviceInfo

    *  objects from the CaptureDeviceManager

    */

   Vector videoDevs = CaptureDeviceManager.getDeviceList(rgbFormat);

 

   /*  Loop through the results and print them out for the user  */

   for (int i = 0; i

 
   /*  We are looking for a format of 160 x 120 pixels with 24 bit

    *  colour depth, RGB

    */

   Dimension wantRes = new Dimension(160, 120);

   int wantDepth = 24;

 

 

   /*  Get the Formats supported by the device. (Real code will check for

    *  a null from getDevice)

    */

   CaptureDeviceInfo device = CaptureDeviceManager.getDevice("webcam:0");

   Format[] fmts = device.getFormats();

   RGBFormat userFormat = null;

 

   for (int i = 0; i
 
   MediaLocator loc = device.getLocator();

   DataSource formattedSource = null;

 

   try {

     formattedSource = Manager.createDataSource(loc);

   } catch (IOException ioe) {

     System.out.println("IO Error creating dataSource");

     System.exit(1);

   } catch (NoDataSourceException ndse) {

     System.out.println("Unable to create dataSource");

     System.exit(1);

   }

 

   /*  Setting the format is rather complicated. Firstly we need to get

    *  the format controls from the dataSource we just created. In order

    *  to do this we need a reference to an object implementing the

    *  CaptureDevice interface (which DataSource objects can).

    */

   if (!(formattedSource instanceof CaptureDevice)) {

     System.out.println("DataSource not a CaptureDevice");

     System.exit(1);

   }

 

   FormatControl[] fmtControls =

     ((CaptureDevice)formattedSource).getFormatControls();

 

   if (fmtControls == null || fmtControls.length == 0) {

     System.out.println("No FormatControl available");

     System.exit(1);

   }

 

   Format setFormat = null;

 

   /*  Now we need to loop through the available FormatControls and try

    *  to set the format to the one we want. According to the documentation

    *  even though this may appear to work, it may fail later on. Since

    *  we know that the format is supported we hope that this won't happen

    */

   for (int i = 0; i

 
 Object stateLock = new Object();  //  This must be a global

 

   //  Method code

 

   Processor deviceProc = null;

 

   try {

     deviceProc = Manager.createProcessor(formattedSource);

   } catch (IOException ioe) {

     System.out.println("Unable to get Processor for device: " +

       ioe.getMessage());

     System.exit(1);

   } catch (NoProcessorException npe) {

     System.out.println("Unable to get Processor for device: " +

       npe.getMessage());

     System.exit(1);

   }

 

   /*  In order to use the controller we have to put it in the realized

    *  state. We do this by calling the realize method, but this will

    *  return immediately so we must register a listener (this class) to

    *  be notified when the controller is ready. The class containing this

    *  code must implement the ControllerListener interface.

    */

   deviceProc.addControllerListener(this);

   deviceProc.realize();

   while (deviceProc.getState() != Controller.Realized) {

     synchronized (stateLock) {

       try {

         stateLock.wait();

       } catch (InterruptedException ie) {

         System.out.println("Device failed to get to realized state");

         System.exit(1);

       }

     }

   }

 

   /*  Finally, start the processor  */

   deviceProc.start();

 
 /**

  *  The ControllerListener interface only contains one method,

  *  controllerUpdate

  **/

 public void controllerUpdate(ControllerEvent ce) {

   if (ce instanceof RealizeCompleteEvent) {

     System.out.println("Realize transition completed");

 

     synchronized (stateLock) {

       stateLock.notifyAll();

     }

   }

 }

 




 
 private PushBufferStream camStream;  //  Global variable

 private BufferToImage converter;     //  Global variable

 

 

   //  Method code

 

   PushBufferDataSource source = null;

 

   try {

     source = (PushBufferDataSource)deviceProc.getDataOutput();

   } catch (NotRealizedError nre) {

     /*  Should never happen  */

     throw new VisionJMFException("Internal error: processor not realized");

   }

 

   /*  getStreams returns all available streams. For frame grabbing this

    *  is usually only one, but we need to check, just in case

    */

   PushBufferStream[] streams = source.getStreams();

 

   /*  Pick the first RGBFormat stream available (shouldn't be more than

    *  one)

    */

   for (int i = 0; i

 
   /**

    *  Get an image from the camera

    **/

   public Image getImage() {

     Buffer b = new Buffer();

 

     try {

       camStream.read(b);

     } catch (IOException ioe) {

       System.out.println("Unable to capture frame from camera");

       return null;

     }

 

     Image i = converter.createImage(b);

     return i;

   }

 
0
kephillipsAuthor Commented:
how do i get a .java page (like the script above) to work within an html page???
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.