Playing and recording

Hi,
I'm writing an application which is supposed to capture video from a webcam, copy it into a file and give the opportunity to watch the video at the same time. I've been able to do these tasks separately but when I try to get them together, catastrophe! BElow is the code:
import java.lang.*;
import java.io.*;
import javax.media.*;
import javax.media.protocol.*;
import javax.swing.*;
import java.util.*;
import javax.media.format.*;
import java.awt.*;
import java.awt.event.*;
import javax.media.bean.playerbean.*;
import com.sun.media.protocol.vfw.VFWCapture;
public class Testeur{
boolean ready=false;
String filename;
javax.media.protocol.DataSource datasource; //attach�e � la webcam
MediaLocator source; //adresse de la webcam
Processor p; //encode en quicktime le produit de datasource
DataSource dsource; //sortie du processeur vers le datasink qui enregistre dans le fichier
MediaLocator dest; //path du fichier de destination
DataSink filewriter;
DataSource ds2;
Vector devices;
public static void main(String []a)     {
     Testeur ts=new Testeur();
     while(!ts.ready){}
     System.out.println("we are ready");
     //create the thread which will take care of the affichage of the flux.
//     Afficheur aff=new Afficheur(ts);
//     System.out.println("displayer created");
//     aff.run();
public DataSource createDSClone(){
     DataSource newbie=null;
     try{
          //newbie=ds2.createClone();//the clone problem
          newbie=Manager.createCloneableDataSource(datasource);
          if(newbie!=null) System.out.println("newbie created!");
          System.out.println("could not clone datasource");
     catch(Exception e){
          System.out.println("exception while cloning datasource");
     return newbie;
     public Testeur(){
     String filename;
javax.media.protocol.DataSource datasource; //attach�e � la webcam
MediaLocator source; //adresse de la webcam
Processor p; //encode en quicktime le produit de datasource
DataSource dsource; //sortie du processeur vers le datasink qui enregistre dans le fichier
MediaLocator dest; //path du fichier de destination
DataSink filewriter;
Vector devices;
     VideoFormat vidformat = new VideoFormat(VideoFormat.RGB);
devices = CaptureDeviceManager.getDeviceList(vidformat);
CaptureDeviceInfo di = null;
if (devices.size() > 0){
          di = (CaptureDeviceInfo) devices.elementAt(0);
          System.out.println("informations :name [] "+di.getName()+" ;;locator [] "+di.getLocator().toString());
else {
JOptionPane.showMessageDialog(null,"Your camera is not connected", "No webcam found", JOptionPane.WARNING_MESSAGE);
System.exit(1);
try{
          //source=di.getLocator();
          //source= new MediaLocator("vfw:Microsoft WDM Image Capture:0");
          source= new MediaLocator("vfw://0RGB");
          System.out.println("Tasker2: locator "+di.getLocator().toString());//ok
          datasource=Manager.createDataSource(source);//does not pass this point
          System.out.println("datasource created!");
          //datasource=Manager.createCloneableDataSource(datasource);
     //     System.out.println("cloneable datasource created!!");
*Le processeur va prendre la sortie de datasource, l'encoder en QuickTime
*Puis, le DataSink va �crire le fichier .mov localis� en dest � partir des
*donn�es  recueillies de source
     try {
          p=Manager.createProcessor(datasource);
     do{
synchronized(p){
     System.out.println("processor created");
     Thread.sleep(20000);
          p.configure();
while(p.getState()!=Processor.Configured){
          p.wait(10000);
p.setContentDescriptor(new FileTypeDescriptor(FileTypeDescriptor.QUICKTIME));
     System.out.println("processor configured");
     break;
while(!Thread.currentThread().isInterrupted());
     System.out.println("starting the wait cycle...");
     try{
     //processor configured, put record code here
     try{
          p.realize();
          do{
synchronized(p){
     System.out.println("processor in the realizing process...");
     Thread.sleep(20000);
while(p.getState()!=Processor.Realized){
          p.wait(10000);
     System.out.println("processor realized");
     break;
while(!Thread.currentThread().isInterrupted());
     if(p.getState()!=Processor.Realized){
          System.out.println("not realized after 100s");
          System.out.println("current state :"+p.getState());
          System.out.println("configured "+p.Configured);
          System.out.println("realizing "+p.Realizing);
          System.out.println("realized "+p.Realized);
          System.exit(1);
     catch(Exception e){
          System.out.println("error while waiting for processor to realize");
          System.out.println("Message : "+e.getMessage()+" exception of type: "+e.getClass().getName());
          datasource.disconnect();
          System.exit(1);
     dsource = p.getDataOutput();
     dest= new MediaLocator( "file:output2.mov" );//instead, use filename variable
     System.out.println("destination media locator created!");
     filewriter = null;
          try {
          filewriter = Manager.createDataSink( dsource, dest );
          if(filewriter!=null) System.out.println("datasink created!");//ok
          filewriter.open();
          System.out.println("open...");
          filewriter.start();
          System.out.println("started...");//ok
          //ready=true;
          Afficheur aff=new Afficheur(this);//never displays, now!
     System.out.println("displayer created");
     aff.run();
          catch ( Exception e ) {
               JOptionPane.showMessageDialog(null,
     "Exception : " + e.getMessage(), "Error", JOptionPane.WARNING_MESSAGE);
                         System.out.println("problem: "+e.getCause().getClass().getName());
                    datasource.stop();
                    datasource.disconnect();
                    System.exit(1);
     p.start();
          try {
               Thread.currentThread().sleep(300000);
          catch (InterruptedException ie) {
          System.out.println("problem prob");
     System.out.println("All done!!");
     //release the ressources
filewriter.stop();
filewriter.close();
p.stop();
p.close();
datasource.stop();
datasource.disconnect();
     catch(Exception prc){
          System.out.println("problem configuring processor.");
     catch ( Exception e ) {
          System.out.println("processor problem"+e.getMessage()+" exception of type: "+e.getClass().getName());
          Thread.sleep(50000);
     catch (Exception e) {//pierre d'achoppement leads me here
JOptionPane.showMessageDialog(null,
"Exception locating media: " + e.getMessage(), "Error", JOptionPane.WARNING_MESSAGE);
System.exit(1);
import java.lang.*;
import java.io.*;
import javax.media.*;
import javax.media.protocol.*;
import javax.swing.*;
import java.util.*;
import javax.media.format.*;
import javax.media.bean.playerbean.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Afficheur extends JFrame implements Runnable , ActionListener {
     Testeur ts;
     MediaPlayer player;
     MediaLocator ml;
     DataSource ds;
     //GUI
     JButton bView, quit;
     JPanel p;
     JComboBox cbx;
     public Afficheur(Testeur testeur){
     super("affichage de flux live");
     ts=testeur;
     //ds=ts.createDSClone();
     ml=ts.source;
     System.out.println("source : "+ml.toString());
     if(ds==null)
     System.out.println("unable to create the clone to the original datasource");//problem source
     //create the GUI
          p=new JPanel(new GridLayout(2,3));
          bView=new JButton("Visualiser camera");
          String [] albus={"vfw:Microsoft WDM Image Capture:0","meenie","minie","moe"};
          cbx=new JComboBox(albus);     
          p.add(cbx)     ;
          p.add(bView);
          setContentPane(p);
          this.setBounds(50,50,100,100);
          bView.addActionListener(this);
     //this.run();
     public void run(){
          //show the GUI and wait for orders.
     this.setVisible(true);     
     public void actionPerformed(ActionEvent e){
          JButton origin= (JButton)e.getSource();
               //determine which cam is selected and launch the player.
          if(origin==bView){
               System.out.println("you are about to view the flux");
               try{
          //     player=new MediaPlayer();//1)
               //player= (MediaPlayer)Manager.createRealizedPlayer(ds);// 2)
               player= (MediaPlayer)Manager.createRealizedPlayer(ml);
               System.out.println("player created");
               Thread.sleep(10000);
               *2) when done this way, we get to the catch clause,
               *with a null message.
               *today, we have a mass exception!
               //player.setDataSource(ds);
               player.setFixedAspectRatio(true);
               player.setBounds(10,10,150,150);
               player.realize();
System.out.println("waiting for player to realize...");
*we keep on waiting here until the Testeur finishes record the 300s of movie
               player.waitForState(300);
               System.out.println("player realized");
               this.getContentPane().add(player.getVisualComponent());
               setBounds(0,0,170,180);
               setVisible(true);
               System.out.println("about to start the player...");
               player.start();
               }catch(Exception et){
                    System.out.println("problem: "+et.getMessage());
                    System.out.println("problem: "+et.toString());
                    System.out.println("problem: "+et.getCause().getClass().getName());
          else{
               if(origin==quit){
                         player.stop();
                         player.close();
                         this.dispose();
Problems:
1)the file cannot be viewed with any of the players I have on my computer: Windows Media Player and Real Player fail to play it. Even JMStudio can't!!
2) when I click on the button to display the video, a null exception is thrown. sometimes, there's a message sayiong the player could not be created.
I'm completely confused with this thing. Advice would be very appreciated!
Thanks!

Hi Mustansar,
I have got the same problem. I use a clone datasource too, but I can not save anything.
Have you resolve it?
If yes, tell me like please
Thanks a lot

Similar Messages

  • Can Express 9 play and record multiple instruments at the same time?

    I have logic express 9 and was told with my interface that I can play and record different instruments at the same time on Express 9. Is this true because I have spent a long time trying to figure out how.

    Hi,
    to record multiple Inputs at a time, open up the appropriate number of audio tracks. Now for each track, select the correct Input in the Channelstrip.
    Now, ARM all these tracks for recording by clicking the little red R in the track header or channelstrip. Now if you hit record, all these tracks should record simultaneously their respective inputs.
    All other existing tracks should playback while recording.
    Fox

  • When I connect my electric acoustic through an audio jack to usb there is a delay between playing and recording. Can this be overcome?

    when I connect my electric acoustic through an audio jack to usb there is a delay between playing and recording. Can this be overcome?

    Hi johnbwebster,
    Welcome to the Support Communities!
    The Logic Express 9 Manual shows how to Adjust the "Recording Delay" in the Audio Preferences:
    Click on the link below for more information and screen shots:
    Logic Express 9 User Manual: Audio Preferences in Logic Express
    https://documentation.apple.com/en/logicexpress/usermanual/index.html#chapter=43 %26section=4%26tasks=true
    Cheers,
    - Judy

  • Can I play and record minecraft on a mac pro

    I am currently playing minecraft on a windows pc with a 1GB graphics card. My graphics card has crashed while playing basic minecraft. I want to buy minecraft so I can do more and also install HD resource packs, but are unable to because of my computer. I have been advised to buy the new Apple Mac Pro, as it has a 6GB graphics card, but am wondering if minecraft will run on it and if so, how well. I also want to record minecraft and put it on youtube, but have noticed that most of the people who play minecraft have pc's to play and record it on. I have also noticed that mojang, who make minecraft are using pc's. Is there anybody who is using an Apple to play and record minecraft and if so, could you let me know how well it works and if you have uploaded it to youtube, please give me your link or username. I am looking at buying the new Mac Pro to run minecraft but am wondering if it will do what I want it to do and if anyone has any advise.
    Thankyou.
    William Evans

    You can only PLAY Blu-ray discs on a Mac by using one of several software's that untilize a Blu-ray license on the internet. What this means is that you must have a fast internet connection to play the disc on your machine. Apple refuses in support Blu-ray with their OS, so there's no way one can play BRD using their computers software in a stand-a-lone manner, like Windows users can.  This is one of those reasons for the love and hate relationships Apple creates  for controlling the market to their advantage, at a loss of one of the most common entertainment formats to their user base. They could easily support the format, they simply chose not to either out of stubborness or for money reasons. The latter makes you winder when they have so much of it now.
    Toast software, on the other hand, has the ability to burn Blu-ray discs, so you can at least use BRD for back-up.  You can also rip movies, etc. I purchased a small and nifty portable BR burner from Sony, Model BDX-S600U that was fairly cheap at the time for $149. It's now $178 at Amazon. It only interfaces witha computer through dual USB though (one is for additonal power), so you can't use it with your TV.  I use this device on my MacBook Air when I want to burn or play DVD's. I have tested the machine and it plays DVD movies and burns just fine. I've been so busy though, that I haven't actualy burned a BR data disc yet, but I know the Toast software supports it. Moreover, hard drives have become so cheap, that burning to BR isn't the best BU, but still uasable and great for mailing large files.
    Unfortunately, until Apple gets their HOOTA we may never see BR support because Tim Cook may just follow Steve Jobs lead out of respect. Yet, with new leadership, and Steve out of the way (Bless him), we may eventually see Apple support. Especially as they continue to merge iOS and OSX. I wouldn't hold your breath on it though.

  • Macbook Pro: Play and record sound at the same time

    Greetings everyone,
    My brother and I have are going to switch go a mac, preferebly to a macbook pro. we used windows so far, but the frustration has grown extremely huge, so it's time to throw off this junk.
    We've been working with sound a lot and many times we recorded any sound which played through the computer: that means sound and music from dvds and games or other sources, we couldn't get anywhere else. What we did is simply letting the game or dvd play and record the audio at the same time.
    I've testet this functionality in windows via bootcamp on a macbook of friend of mine, but NOT the macbook pro version. It's wasn't really that good as I thought. Sound quality was below what I'd expect.
    So here are my questions:
    - Does the macbook pro have a better sound card, which enables simultaneos play + record?
    - Is good record quality bound to a software I need to use?
    Thanks for your replies.

    Apple don't have separate "sound cards" like PC's , Martin. The necessary hardware is proprietary , and built into the logic boards.
    Both of them have high quality combined optical digital input and audio line in, and combined optical digital output and audio line out. You can also attach various USB or firewire audio input and output devices if you wish. So as far as 'quality" goes, it depends what you are playing them through more than anything else. The inherent audio abilities of both are pretty danged good when using Mac specific software. That is why the music industry love 'em!
    Or are you just talking about sound quality through the built in speakers, which are, of course severely limited by the amount of space available, though I've heard far worse from many PC notebooks!?
    Cheers
    Rod

  • Playing and recording sound

    Hello, I am completelly new in Java programing. I was assigned to search for how to play and record sound in an appliation in Java, can somebody help me?
    Thanks

    http://www.google.com.au/search?hl=en&q=java+play+sound&btnG=Google+Search&meta=
    http://www.google.com.au/search?hl=en&q=java+record+sound&btnG=Google+Search&meta=

  • Simultaneously Play and Record.

    Hi
    I'm working on a application where I need simultaneously Play and Record.
    I followed the code of 'SpeakHere'. I got some success also. It is playing and recording simultaneously, but the problem is it plays audio through headphone speaker while recording. I wanted it to play through external speaker.
    thanks.

    That is, literally, all the code I have behind my "Enable Speaker" button. Are you sure you've set the Audio Session's category beforehand, and enabled it?
    I see you're using the SpeakHere sample code. It does take care of setting up the audio session and enabling it. But it uses the "Media Playback" category of the audio session, rather than the "Play and Record" category.
    Look for all the places in SpeakHere where they set the audio session's category (for playback) and change it to the "Play and Record" category. The property I mentioned above only takes effect in this category.
    Good luck! If you're still having trouble, a chunk of code or some NSLog output might be helpful.

  • Play and record simultaniously

    is it possible to play a song in a app and record video and/or sound within a app at the same time in a windows phone app? it works in windows 8 and since windows phone 8 has similar device capabilities I was wondering if it is possible.

    Hello
    When I first read your post, I couldn't believe it is possible to achieve without using C++ and WASAPI stuff. I immediatealy implemented it and launched on the emulator. I was really amazed how perfectly it worked (on the emulator). That was exactly
    the behavior I wanted and tried to implement in various ways for more than 4 months for now.
    Unfortunately, when I deployed it to the device I found out some imperfections that couldn't have been experienced on emulator.
    First, the music was playing from this quiet speaker used for regular phone calls (the one above the screen). The sound quality is poor, quiet and - which is more important - the volume up and down hardware buttons control the In-voice volume (10 possible
    settings) rather than Multimedia/apps one (30 possible settings). Even when I connected the headphones, the maximum sound volume was not even close to the one I could achieve using Multimedia/apps volume control.
    Second, the music playback stutters. I first though the phone is just overloaded with simultaneous music playback and video recording (with preview enabled), so I totally disabled the video preview and recording. Unfortunately, the audio playback still frequently
    stuttered. I found it always does when mediaElement.AudioCategory is set to Communications, no matter if video recording is on.
    Trying to fix out the first issue, I used both
    mediaElement.AudioDeviceType = AudioDeviceType.Multimedia;
    and
    mediaElement.AudioDeviceType = AudioDeviceType.Console;
    with no results. The music still played only from this phone call speaker above the screen. Then I tried using all the possible AudioCategories enumerations. Any other than Communications blocks simulataneous video recording, so I didn't use them.
    To try to fix the second issue, I used
    mediaElement.RealTimePlayback = true;
    but the playback still stutters :(.
    Is it possible to solve at least the second issue with the stuttering playback? It is unacceptable in my scenario to have the playback interrupted in any way. It is strange since the phone is not overloaded and the stuttering is not present when the AudioCategory
    is set to any other value. Or when the application is launched on the emulator...
    Many thanks in advance and Happy Easter :)
    Maciek

  • Unable to view Play and records buttons

    I am unable to view the bar with play, record, stop etc.

    Just position your cursor on the bottom edge of the Arrange window until your cursor appears as a solid black line with an arrow pointing up from the middle. Then either double-click or click and drag up until the Transport appears. You can also open the Transport in a separate window using CMD+7 or going to Window/Transport.
    Cheers

  • Latence while playing and recording (Axiom 49)

    Hello,
    When i try to play with my Axiom 49 while playing a song or while trying to record myself, there is lag and I need to wait a little time before hearing the sound of my instrument. Also i need to press the key a certain time before i can hear the sound.
    My keyboard is plugged directly in my MacBook Pro, the problem is not coming from the computer, i think there something to do in Logic but i don't know what to do .
    Is there any way to change this ?
    Pierre

    Hello,
    I found a solution, a complete reinstallation of Logic solve the problem.

  • Playing and Recording while minimized

    I've noticed that Adobe Audition 3.0 will stop recording or playing when I open another window, or if I minimize it
    I looked this up in the forums, and found a solution of unchecking the "Release ASIO driver in background" button. I've tried that, but the problem is persisting.
    I've noticed that this is happening on two different computers, on the same edition. Is there anything else I should be trying here?

    http://www.google.com.au/search?hl=en&q=java+play+sound&btnG=Google+Search&meta=
    http://www.google.com.au/search?hl=en&q=java+record+sound&btnG=Google+Search&meta=

  • Xperia Z Tablet Video play and record problem

    Hello, I have a problem with xperis of the tablet . When shooting video is uploaded black screen and green bar at the top. Likewise, I do not play video . Video recorded from the Z1 Compact And sena to Z tablet, is not played on video app sony, or photo app from google, but I play him in BS Player. I try faktory restore. No change. Plese hele me. I have 4.4.4 kitkat

    Sorry to hear that you have issues playing videos.
    I recommend that you first try to repair the software in your tablet using a computer and PC Companion or Bridge for Mac: http://support.sonymobile.com/global-en/xperiatabletz/software/ but please note that this will delete all data on your tablet.
    If the issue should still remain I think that this needs to be examined and fixed at a repair center. For more information about how to submit your tablet for repair and where, contact your local support team.
     - Official Sony Xperia Support Staff
    If you're new to our forums make sure that you have read our Discussion guidelines.
    If you want to get in touch with the local support team for your country please visit our contact page.

  • Is Simultaneous Playing and Recording Impossible in Vis

    I have been scouring these forums for answers why this Sound Blaster X-Fi card running in Windows Vista can not record from an internal source, (Analog Mix, or What U Hear.) So far,all I found was that the Creative FAQ says that the Xtreme and Titanium cards are "excluded" from having "What U Hear" as a recording source. Did I read this right
    When is Creative going to release drivers that will allow me do do this thing that nearly all previous cards cound do, going back to the Sound Blaster Live Do you realize that the card is useless to me if I can't record from an internal source
    I look forward to your prompt response.

    You read it right I'm afraid.
    The *official* reply on these forums was in this thread.
    Both the X-Fi Platinum and Fatalty Champion Series have the "What U Hear" recording option in Vista or XP environment. There shouldn't be any difference in music production as both cards uses the same chipset. If you are into music production, I would suggest taking a look at the EMU systems too.
    I don't think this is a driver fix either.
    Funny you should mention the Li've as that can do "What U hear" with some drivers written by a guy who used to come on here.
    It really needs someome like him to look at this issue and tell us whether a driver work round would do it, but given as many other cards don't do it in Vista I have my doubts.
    Just seems the way sound chips work these days.
    The X-Fi XtremeMusic that Creative no longer make has it.

  • Garageband Pauses on play and record

    I've been running Garageband successfully for about a year on an old G5 running 10.5.8 and recently it's been stopping while playing, pausing for about 2 seconds then starting again. The play marker drops back a few seconds each time and this happens - on large and small mixes - every 10 seonds or so.
    Most people reckons this is related to RAM, but I have 2 GB which has always been absolutely fine and with GB open is only half used. Similarly the marker stays white the whole time. I cleaned the system with Onyx, repaired permissions, started in Safe mode, removed recently installed programs and done all of the other stuff that has been recommended, but the behaviour still continues.
    Anybody have any clues? It's driving me mad.

    Hello hywelt,
    Thank you for the details of the issue you are experiencing with Garageband.  You have taken some really good troubleshooting steps already, but I found an article with a few additional steps you can take to troubleshoot this issue.
    I recommend reviewing the following article:
    iLife: Troubleshooting Basics
    http://support.apple.com/kb/ts3249
    Thank you for using Apple Support Communities.
    Best,
    Sheila M.

  • Well i am going to get a macbook pro non-retina should i get 4gb or 8gb i asked because i have lots of files and i play and record games what gb should i do?

    i have to get a new computer i want to get a macbook pro non retina but i use my computer alot with school i have lots of files and picture but what should i get 4gb or 8gb

    You need storage space for your files. You need RAM in order to run programs. They are not the same.
    1. Get 8 GBs of RAM.
    2. Get a large hard drive or SSD to store your files. The bigger, the better.

Maybe you are looking for

  • Table for getting pricing data in sales order

    Dear experts how to get red mark field data for an ZREPORT in KONV i am unable to get this data Regards Abhi

  • Can´t connect to WiFi when other Mac users can (in Spain)

    Two days ago I went to a coffeeshop with free wifi in Spain and had no trouble using my Airport menubar logo to log on using their network and password. Just type it into the box, press Return, and presto, no problems. Today I get Connection timeout

  • Dynamic Measure - Selecting which fields to include in a calculation

    Hello all, and thank you so much for spending your time reading this. I'm working on PowerPivot in Excel 2010. But if you know there's a solution in 2013, please let me know and I'll try to justify an upgrading. I have a table for my data source wher

  • Upgraded to 1.4 now applets dont work

    I used to be able to work with applets in my web browser. Now since i have upgraded to 1.4 it seems none of them work any more. Though I can compile and run java apps Any ideas? Thanks

  • Processing Dimension Members

    hi to all experts here in SDN Community, I just want to ask for help regarding in processing the dimension members, My problem is whenever i try to process a dimension i get an error like this: "public member 'GetOnlyFormulaValidate' on type 'frmMemb