getting jmf to read rtsp

T

torbs

How can I get JMF to read a rtsp stream and displaying the content in a
player.

I have modified the code in JMF's documentation, but the documentation
for rtsp is not very good. I need to find a way to read rtsp streams.
I have tried Quicktime for Java, but I would really like to find a way
to display content that every platform can read.

I have installed the ffmpeg mpeg 4 codec for jmf.

Tor

CODE:

import java.applet.*;
import java.awt.*;
import java.net.*;
import javax.media.*;

public class PlayerApplet extends Applet implements ControllerListener
{
Player player = null;
public void init() {
setLayout(new BorderLayout());
String mediaFile =

"rtsp://lillestroem.uio.no/div/imk/strekktekst/320/L1M2.mp4";
try {

MediaLocator mrl= new MediaLocator(mediaFile);


player = Manager.createPlayer(mrl);
player.addControllerListener(this);
}
catch (Exception e) {
System.err.println("Got exception "+e);
}
}
public void start() {
player.start();
}
public void stop() {
player.stop();
player.deallocate();
}
public void destroy() {
player.close();
}
public synchronized void controllerUpdate(ControllerEvent event) {
if (event instanceof RealizeCompleteEvent) {
Component comp;
if ((comp = player.getVisualComponent()) != null)
add ("Center", comp);
if ((comp = player.getControlPanelComponent()) != null)
add ("South", comp);
validate();
}
}
}
 
R

Roedy Green

import java.applet.*;
import java.awt.*;
import java.net.*;
import javax.media.*;

public class PlayerApplet extends Applet implements ControllerListener
{
Player player = null;
public void init() {
setLayout(new BorderLayout());
String mediaFile =

"rtsp://lillestroem.uio.no/div/imk/strekktekst/320/L1M2.mp4";
try {

MediaLocator mrl= new MediaLocator(mediaFile);


player = Manager.createPlayer(mrl);
player.addControllerListener(this);
}
catch (Exception e) {
System.err.println("Got exception "+e);
}
}
public void start() {
player.start();
}
public void stop() {
player.stop();
player.deallocate();
}
public void destroy() {
player.close();
}
public synchronized void controllerUpdate(ControllerEvent event) {
if (event instanceof RealizeCompleteEvent) {
Component comp;
if ((comp = player.getVisualComponent()) != null)
add ("Center", comp);
if ((comp = player.getControlPanelComponent()) != null)
add ("South", comp);
validate();
}
}
}

I modified your code slightly to make it easier to see what is going
on:

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import javax.media.*;

public class PlayerApplet extends Applet implements ControllerListener
{
Player player = null;
public void init()
{
setLayout(new BorderLayout());
String mediaFile =

"rtsp://lillestroem.uio.no/div/imk/strekktekst/320/L1M2.mp4";
try
{

MediaLocator mrl= new MediaLocator(mediaFile);


player = Manager.createRealizedPlayer(mrl);
System.out.println( "player created" );
player.addControllerListener(this);
}
catch ( Exception e )
{
System.err.println("Got exception "+e);
}
}
public void start()
{
player.start();
System.out.println( "player started" );

}
public void stop()
{
player.stop();
player.deallocate();
}
public void destroy()
{
player.close();
}

public synchronized void controllerUpdate(ControllerEvent event)
{
System.out.println( "player event" + event );

if ( event instanceof RealizeCompleteEvent )
{
Component comp;
if ( (comp = player.getVisualComponent()) != null )
add ("Center", comp);
if ( (comp = player.getControlPanelComponent()) != null )
add ("South", comp);
validate();
}
}

/**
* Allow this Applet to run as as application as well.
*
* @param args
* command line arguments ignored.
*/
public static void main ( String args[] )
{
final PlayerApplet applet = new PlayerApplet();
Frame frame = new Frame( "JMF Player" );
frame.setSize( 100, 100 );
applet.init();
frame.add( applet );
frame.validate();
frame.setVisible( true );
applet.start();
frame.addWindowListener( new WindowAdapter()
{

/**
* Handle request to shutdown.
*
* @param e
* event giving details of
closing.
*/
public void windowClosing (
WindowEvent e )
{
applet.stop();
applet.destroy();
System.exit( 0 );
} // end WindowClosing
} // end anonymous class
); // end addWindowListener line
} // end main

}


I got a CannotRealize exception. Can you find some other RTSP source
you know is working? Do you have some other RTSP software you can use
to test your source?

However, I think the source of your problem is that that format is not
natively supported. See
http://java.sun.com/products/java-media/jmf/2.1.1/formats.html
 
T

torbs

Yes, jmf do not support mp4, but I have innstalled both ibm's mp4
codec for jmf and the ffmpeg mpeg 4 codec for jmf.

I have tried the source in quicktime for java so I know it is ok, but
quicktime for java do not exist in linux.
 
R

Roedy Green

Yes, jmf do not support mp4, but I have innstalled both ibm's mp4
codec for jmf and the ffmpeg mpeg 4 codec for jmf.

What's the deal on licensing? The MP-4 folk were demanding royalties
for every play.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top