Jmf on the server side, quicktime as a web client

The java media framework still rocks. As part of my final year project I had to build a streaming server that could stream live video and audio to online clients. I didn’t want to use jmf on the client side due to the ubiquitous applet “sand box”; yuk! I took a look at various embeddable players and settled on QuickTime for one thing: It can play streams when handed their descriptions in the SDP (Session Description Protocol) format.

Here is my workaround, for anyone who may face a similar challenge:

Assumptions:

  1. I assume you know the java media framework and can build an application to stream video and audio using the jmf APIs.
  2. I also assume you can comfortably code using the java servlet api
  3. I assume you want to stream to web clients (embedded QuickTime) from your jmf application

Now lets go …

  1. Check out how to describe the streams you’re sending out from your application in the SDP format (Session Description Protocol). Of course Google exists for such a time as this. Here is a sample from what I did :

    v= 0

    o=Solomons session IN IP4 192.168.1.2

    s=Test Session

    t=0 0

    c=IN IP4 224.124.100.100/2

    m=video 2222 RTP/AVP 26

  2. Put your version of the above description in a text file and name it whatever you want. It would help to end the name with a “.SDP” extension though.
  3. In your java web application, place this text file preferably in the web folder. I assume you are using netbeans here.
  4. The next step is this : You code a java servlet that simply sets it’s content type to “application/sdp;charset=UTF-8″ and then spits out the content of your sdp file to whoever is calling.

    Here is something I did, in case you can read strange signs:


    protected void processRequest(HttpServletRequest request, HttpServletResponse response)

    throws ServletException, IOException {

    response.setContentType(“application/sdp;charset=UTF-8″); // setting
    content
    type to sdp

    File f = new File(getServletContext().getRealPath(“/lecturePage/test2.sdp”)); //getting the sdp file from the location I placed it

    BufferedReader reader = new BufferedReader(new FileReader(f));

    PrintWriter out = response.getWriter();

    try {

    String s = ” “;

    while(s.length() >=1){

    s=reader.readLine();

    out.println(s); //spitting out whatever is read from the file

    }

    reader.close();

    } finally {

    out.close();

    }

    5. Now you need to create the webpage that will have your embedded QuickTime player and set the parameters. As usual, Google exists for this task. But it is worth mentioning that the src parameter you give the embedded player should be the URL to the servlet mentioned above.

    6. Now start your streaming server, start your java web server containing that servlet and the sdp file. In my case, for demonstration purposes I accessed the web page from a different machine

    Note : As you stream from your application, QuickTime is able to decipher the contents of your sdp file and hook onto the appropriate ports etc and render the incoming packets ….

    VOILA ! …

    Here is my live streaming server, built on the netbeans platform. Boy, I love the netbeans platform!

    Here comes the client …

    That’s me sitting at the client machine with camera fixed on me capturing a screen shot

How to use Java Persistence API with netbeans rich client applications.

Hi guys,
I think you might be interested in this:

I worked on a project just last week and chose to use the netbeans platform and JPA.
This was my final workaround and some points to note:
I first created a java class library (from the netbeans java templates), just a normal java class library. I then added a persistence unit, just right clicking and choosing add >> persistence unit.
I created my entity classes and in a different package, created a class that exposed methods for adding,updating and deleting information using the entitymanager.

In my netbeans module that sought to do database related stuff, I created a library wrapper class for the java class library just created and created a dependency on it.
From there I could then have access to the class that exposed the methods for adding, updating and deleting. It seems to me each netbeans module uses its own class loader, cos from here if you run the application, there is a class definition error or something implying the persistence classes cannot be found. Take heart, follow on…

My workaround
Go to tools >> libraries and look for Toplink Essentials. Check the classpath and notice the paths to all the jar files there. Create a new netbeans library wrapper project and include all the jar files there. Create a depency on this library wrapper project for any netbeans module that dares to call the class using the persistence. By this, a definition of the persistence is available to pacify anything that requests a definition of it.

Hi

I am a fan of java. And I will be for a very long time. Currently in my final year of the university, doing computer science. I will be posting across some solutions to those tweeny tiny problems I think most “coders” new to java will face. I am also a big fan of the java media framework. I am one of those still praising the Lord for netbeans, and hope to create some plugins for it very soon… When I’m through with my final year project. Catch ya later.