Java Media Framework 2.1 - Sample Code

   

JMF 2.1 Documentation


This release includes the following JMF samples:

  • JMFRegistry is a standalone Java application you can use to configure JMF.

  •  
  • SimplePlayerApplet is a simple applet that can be used to run a JMF player for a particular media file.

  •  
  • JMStudio demonstrates how to use the JMF 2.1 API to play, capture, transcode, and write media data, as well as how to use the RTP APIs to receive and transmit media data across the network.

  •  
  • Export is a stripped down version of JMStudio to demonstrate transcoding from an arbitrary input source to a file, network or for previewing.

  •  
  • MediaPlayer bean simplifies the task of programming the Player.

  •  
  • RTPPlayerApplet demonstrates how to present RTP streams.

  •  
  • RTPSocketPlayer allows users to use RTP independent of the network transport protocol.

  •  
  • Plugin Samples include sample code to implement JMF plugins.
JMF DiagnosticsSetup
JMFRegistry

JMFRegistry is a standalone Java application used to configure JMF.  You can use it to query and manage the list of media handlers, plugin components and capture devices.

JMFRegistry is built with the Swing GUI toolkit.  To run it requires Java 2 or JDK 1.1.x with Swing 1.1 or above:

  1. Set the CLASSPATH and LD_LIBRARY_PATH as described in Setting Up JMF.   (Be sure to also include the Swing classes in your CLASSPATH if you are using Swing).

  2.  
  3. On the command line, enter:
  4. java JMFRegistry

For more information about how to use JMFRegistry, see the JMFRegistry Guide.

To download the source code for JMFRegistry (and JMStudio):


SimplePlayerApplet

SimplePlayerApplet is a simple applet that can be used to run a JMF player for a particular media file. The URL for the media file is passed in
as a parameter in the applet tag used to display the applet.

This applet embeds the visual component and control panel component in the browser page, if they are available.

The Applet tag for SimplePlayerApplet would look something like:

      <applet code=SimplePlayerApplet.class width=640 height=510>
      <param name=file value="file:/usr/local/media/playme.mov">
      </applet>

See SimplePlayerApplet.java for source code.
 

JMStudio

JMStudio is a standalone Java application built using JMF.  You can use it to play, capture, transcode, and store media data. It also supports RTP reception and transmission.

To run JMStudio:

   1.Set the CLASSPATH and LD_LIBRARY_PATH as described in Setting Up JMF.
   2.On the command line, enter:

          java JMStudio

If you have installed the performace packs, you can also use the JMStudio launch scripts to start the application.

JMStudio can also be used as an external helper application for popular browsers.  The browser will download the file and then launch JMStudio to play the multimedia content from the locally stored file.  To do set up JMStudio as a helper application, edit your applications preferences in your browser, specifying JMStudio as the helper application for each media type you want to play using JMF.

For more information about how to use JMStudio, see the JMStudio User's Guide.

To download the source code for JMStudio (and JMFRegistry):


Export

Export is a stripped down version of JMStudio. It allows a user to specify an arbitrary input source for transcoding. The user can specify the target data formats and output content types. The transcoded result can be sent to a file, the network or just previewing on screen.

To run Export:

   1.Set the CLASSPATH and LD_LIBRARY_PATH as described in Setting Up JMF.
   2.On the command line, enter:

          java Export

The source code for Export is included in the JMStudio source for JMF 2.1.1.
 

MediaPlayer Bean

The MediaPlayer Java Bean is part of the API in the javax.media.bean.playerbean package.  MediaPlayer can be instantiated directly and used to present one or more media streams.

For more information on how to incorporate MediaPlayer in a java application, see the MediaPlayer Guide.
 

RTPPlayerApplet

RTPPlayerApplet is a sample applet that can play unicast, boradcast, and multicast RTP session. To run RTPPlayerApplet, you can use the AppletViewer to open the rtpclient page:

appletviewer rtpclient.html
Off

JMF Players are created for all of the RTP streams in the session. You can use the control components to stop and start playback of the RTP streams.

See RTPPlayerApplet.java for source code.
 

RTPSocketPlayer

This sample allows users to use the network transport protocol independence of JMF in RTP. Users can run RTP over any underlying transport protocol. By default, JMF uses RTP over UDP. Users running RTP over a non UDP transport, can use the RTPSocket object defined in javax.media.rtp.RTPSocket and its accompanying interfaces.

The RTPSocketPlayer.java sampleapp explains the use of the RTPSocket using UDP as its underlying protocol. To use the sample, users need to change the address and port to that of their RTP session. The variables "address" and "port" (line 50) need to match those your RTP server is streaming data to. Recompile the file and run RTPSocketPlayer as

java RTPSocketPlayer
  • The RTPSocket will stream data over from UDP to the RTPSessionManager
  • Only the first stream received on the session is played back in this case.

See RTPSocketPlayer.java for source code.
 

Plugin Samples

Plugins are used to extend the capabilities of JMF as described in the "Extending JMF" chapter of the Programmer's Guide.  A few sample plugins are provided here as reference: