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:


  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

    s=Test Session

    t=0 0

    c=IN IP4

    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
    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){


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



    } finally {



    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


5 thoughts on “Jmf on the server side, quicktime as a web client

  1. That’s very cool. I want to be able to stream to web client, too. Does that mean you will need to place the SDP file in the client server?

    Do you know if I can use JMF to write a RTSP server?


    • I really don’t get your first question but let me attempt to answer as I understand it. The above example streams to a web client, the only issue is that it uses multicasting, which may not be allowed on most corporate networks. There should be a way for jmf to send a unicast stream to a client using sockets. In that case then the issue with multicasting is solved. You could find out from the jmf book

      ” Does that mean you will need to place the SDP file in the client server?”
      In the above example I used a file which I placed on the web server. I simply retrieved the contents with code and sent it to the client. You can as well just use a string variable. For example :

      String sdp = “v= 0” + EOF + “o=Solomons session IN IP4″ + EOF +”s=Test Session” +
      EOF + “t=0 0 ” + EOF + “c=IN IP4 ” + EOF + “m=video 2222 RTP/AVP 26” + EOF.

      ** EOF is the End Of Line character. It seems it’s “\r\n” or something like that. You can find out.

      Then instead of all that code to read from a file we could just say :

      The important thing is to set the content type of your servlet to SDP, and this statement does that :

      ” Do you know if I can use JMF to write a RTSP server? ”
      Yes, I believe you can. I set out to do that for the above project but time wasn’t on my side, so when I discovered that quicktime can directly decode and play SDP files, then I came up with the above and it worked. You would really help the community if you create the rtsp server in java. Please let me know if you set out on that project.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s