receive vedio using applet..
Hi..
am implementing a programm that send a vedio from one pc to another using JMF..
I use theAVTransmit2.java to yranmit vedio from first pc (i will call it the sender pc) , and i want to receive the vedio using applet at the second pc ( i will call it the receiver) using the file calledStudentLiveLectureva..
So i put the code at AvReceive at this applet (StudentLiveLecture.java)..
So when i run this applet at the Receiver pc to receive vedio from the transmitter PC the apllet show this error..
Open RTP session for: addr: 192.168.0.1 port: 2222 ttl: 1
Cannot create the RTP Session: Local Data AddressDoes not belong to any of this hosts local interfaces
Failed to initialize the sessions.
Exiting AVReceive2
And the Applet don't receive any thing,, i don't know why?
Can any body help me at this applet since i don't have alot experience at the applets..
The code here..
1) the AVTransmit2.java
http://java.sun.com/products/java-media/jmf/2.1.1/solutions/AVTransmit.html
2)The AVReceive2.java
http://java.sun.com/products/java-media/jmf/2.1.1/solutions/AVReceive.html
3)StudentLiveLecture.java
import java.io.*;
import java.awt.*;
import java.net.*;
import java.awt.event.*;
import java.util.Vector;
import javax.media.*;
import javax.media.rtp.*;
import javax.media.rtp.event.*;
import javax.media.rtp.rtcp.*;
import javax.media.protocol.*;
import javax.media.protocol.DataSource;
import javax.media.format.AudioFormat;
import javax.media.format.VideoFormat;
import javax.media.Format;
import javax.media.format.FormatChangeEvent;
import javax.media.control.BufferControl;
publicclass StudentLiveLectureextends javax.swing.JAppletimplements ReceiveStreamListener, SessionListener,
ControllerListener{
String sessions[] ={"192.168.0.1/2222"};
RTPManager mgrs[] =null;
Vector playerWindows =null;
boolean dataReceived =false;
Object dataSync =new Object();
/** Initializes the applet StudentLiveLecture */
publicvoid init(){
try{
java.awt.EventQueue.invokeAndWait(new Runnable(){
publicvoid run(){
initComponents();
}
});
}catch (Exception ex){
ex.printStackTrace();
}
}
publicvoid start(){
try{
java.awt.EventQueue.invokeAndWait(new Runnable(){
publicvoid run(){
if (!initialize()){
System.err.println("Failed to initialize the sessions.");
}
// Check to see if AVReceive2 is done.
try{
while (!isDone())
Thread.sleep(1000);
}catch (Exception e){}
System.err.println("Exiting AVReceive2");
}
});
}catch (Exception ex){
ex.printStackTrace();
}
}
/** This method is called from within the init() method to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
privatevoid initComponents(){//GEN-BEGIN:initComponents
jPanel1 =new javax.swing.JPanel();
jScrollPane1 =new javax.swing.JScrollPane();
jTextArea1 =new javax.swing.JTextArea();
jButton1 =new javax.swing.JButton();
jButton2 =new javax.swing.JButton();
jButton3 =new javax.swing.JButton();
jButton4 =new javax.swing.JButton();
jProgressBar1 =new javax.swing.JProgressBar();
jSlider1 =new javax.swing.JSlider();
jLabel2 =new javax.swing.JLabel();
jSeparator1 =new javax.swing.JSeparator();
jButton5 =new javax.swing.JButton();
jButton6 =new javax.swing.JButton();
jTextArea2 =new javax.swing.JTextArea();
jLabel1 =new javax.swing.JLabel();
jButton7 =new javax.swing.JButton();
jSeparator2 =new javax.swing.JSeparator();
getContentPane().setLayout(null);
jPanel1.setBackground(new java.awt.Color(255, 255, 255));
jPanel1.setForeground(new java.awt.Color(153, 204, 255));
getContentPane().add(jPanel1);
jPanel1.setBounds(40, 40, 450, 230);
jScrollPane1.setViewportView(jTextArea1);
getContentPane().add(jScrollPane1);
jScrollPane1.setBounds(40, 400, 370, 120);
jButton1.setFont(new java.awt.Font("Microsoft Sans Serif", 1, 14));
jButton1.setText("Send");
getContentPane().add(jButton1);
jButton1.setBounds(420, 470, 80, 40);
jButton2.setFont(new java.awt.Font("Microsoft Sans Serif", 1, 14));
jButton2.setText("Font");
getContentPane().add(jButton2);
jButton2.setBounds(420, 410, 80, 40);
jButton3.setFont(new java.awt.Font("Microsoft Sans Serif", 1, 14));
jButton3.setText("Record Lecture");
getContentPane().add(jButton3);
jButton3.setBounds(50, 290, 180, 40);
jButton4.setFont(new java.awt.Font("Microsoft Sans Serif", 1, 14));
jButton4.setText("Voice");
getContentPane().add(jButton4);
jButton4.setBounds(570, 510, 90, 30);
getContentPane().add(jProgressBar1);
jProgressBar1.setBounds(580, 370, 20, 140);
jSlider1.setOrientation(javax.swing.JSlider.VERTICAL);
getContentPane().add(jSlider1);
jSlider1.setBounds(610, 370, 50, 140);
jLabel2.setFont(new java.awt.Font("Microsoft Sans Serif", 1, 14));
jLabel2.setText("Teacher");
getContentPane().add(jLabel2);
jLabel2.setBounds(50, 20, 80, 16);
getContentPane().add(jSeparator1);
jSeparator1.setBounds(10, 550, 650, 2);
jButton5.setFont(new java.awt.Font("Microsoft Sans Serif", 1, 14));
jButton5.setText("LogOff");
getContentPane().add(jButton5);
jButton5.setBounds(400, 570, 170, 40);
jButton6.setFont(new java.awt.Font("Microsoft Sans Serif", 1, 14));
jButton6.setText("Back");
getContentPane().add(jButton6);
jButton6.setBounds(150, 570, 170, 40);
getContentPane().add(jTextArea2);
jTextArea2.setBounds(500, 90, 150, 140);
jLabel1.setFont(new java.awt.Font("Microsoft Sans Serif", 1, 14));
jLabel1.setText("Student Picture");
getContentPane().add(jLabel1);
jLabel1.setBounds(520, 50, 120, 16);
jButton7.setFont(new java.awt.Font("Microsoft Sans Serif", 1, 14));
jButton7.setText("Chat with Teacher");
getContentPane().add(jButton7);
jButton7.setBounds(280, 290, 180, 40);
getContentPane().add(jSeparator2);
jSeparator2.setBounds(10, 340, 650, 10);
}//GEN-END:initComponents
protectedboolean initialize(){
try{
InetAddress ipAddr;
SessionAddress localAddr =new SessionAddress();
SessionAddress destAddr;
mgrs =new RTPManager[sessions.length];
playerWindows =new Vector();
SessionLabel session;
// Open the RTP sessions.
for (int i = 0; i < sessions.length; i++){
// Parse the session addresses.
try{
session =new SessionLabel(sessions[i]);
}catch (IllegalArgumentException e){
System.err.println("Failed to parse the session address given: " + sessions[i]);
returnfalse;
}
System.err.println(" - Open RTP session for: addr: " + session.addr +" port: " + session.port +" ttl: " + session.ttl);
mgrs[i] = (RTPManager) RTPManager.newInstance();
mgrs[i].addSessionListener(this);
mgrs[i].addReceiveStreamListener(this);
ipAddr = InetAddress.getByName(session.addr);
if( ipAddr.isMulticastAddress()){
// local and remote address pairs are identical:
localAddr=new SessionAddress( ipAddr,
session.port,
session.ttl);
destAddr =new SessionAddress( ipAddr,
session.port,
session.ttl);
}else{
localAddr=new SessionAddress( InetAddress.getLocalHost(),
session.port);
destAddr =new SessionAddress( ipAddr, session.port);
}
mgrs[i].initialize( localAddr);
// You can try out some other buffer size to see
// if you can get better smoothness.
BufferControl bc = (BufferControl)mgrs[i].getControl("javax.media.control.BufferControl");
if (bc !=null)
bc.setBufferLength(350);
mgrs[i].addTarget(destAddr);
}
}catch (Exception e){
System.err.println("Cannot create the RTP Session: " + e.getMessage());
returnfalse;
}
// Wait for data to arrive before moving on.
long then = System.currentTimeMillis();
long waitingPeriod = 30000;// wait for a maximum of 30 secs.
try{
synchronized (dataSync){
while (!dataReceived &&
System.currentTimeMillis() - then < waitingPeriod){
if (!dataReceived)
System.err.println(" - Waiting for RTP data to arrive...");
dataSync.wait(1000);
}
}
}catch (Exception e){}
if (!dataReceived){
System.err.println("No RTP data was received.");
close();
returnfalse;
}
returntrue;
}
publicboolean isDone(){
return playerWindows.size() == 0;
}
/**
* Close the players and the session managers.
*/
protectedvoid close(){
for (int i = 0; i < playerWindows.size(); i++){
try{
((PlayerWindow)playerWindows.elementAt(i)).close();
}catch (Exception e){}
}
playerWindows.removeAllElements();
// close the RTP session.
for (int i = 0; i < mgrs.length; i++){
if (mgrs[i] !=null){
mgrs[i].removeTargets("Closing session from AVReceive2");
mgrs[i].dispose();
mgrs[i] =null;
}
}
}
PlayerWindow find(Player p){
for (int i = 0; i < playerWindows.size(); i++){
PlayerWindow pw = (PlayerWindow)playerWindows.elementAt(i);
if (pw.player == p)
return pw;
}
returnnull;
}
PlayerWindow find(ReceiveStream strm){
for (int i = 0; i < playerWindows.size(); i++){
PlayerWindow pw = (PlayerWindow)playerWindows.elementAt(i);
if (pw.stream == strm)
return pw;
}
returnnull;
}
/**
* SessionListener.
*/
publicsynchronizedvoid update(SessionEvent evt){
if (evtinstanceof NewParticipantEvent){
Participant p = ((NewParticipantEvent)evt).getParticipant();
System.err.println(" - A new participant had just joined: " + p.getCNAME());
}
}
/**
* ReceiveStreamListener
*/
publicsynchronizedvoid update( ReceiveStreamEvent evt){
RTPManager mgr = (RTPManager)evt.getSource();
Participant participant = evt.getParticipant();// could be null.
ReceiveStream stream = evt.getReceiveStream();// could be null.
if (evtinstanceof RemotePayloadChangeEvent){
System.err.println(" - Received an RTP PayloadChangeEvent.");
System.err.println("Sorry, cannot handle payload change.");
System.exit(0);
}
elseif (evtinstanceof NewReceiveStreamEvent){
try{
stream = ((NewReceiveStreamEvent)evt).getReceiveStream();
DataSource ds = stream.getDataSource();
// Find out the formats.
RTPControl ctl = (RTPControl)ds.getControl("javax.media.rtp.RTPControl");
if (ctl !=null){
System.err.println(" - Recevied new RTP stream: " + ctl.getFormat());
}else
System.err.println(" - Recevied new RTP stream");
if (participant ==null)
System.err.println("The sender of this stream had yet to be identified.");
else{
System.err.println("The stream comes from: " + participant.getCNAME());
}
// create a player by passing datasource to the Media Manager
Player p = javax.media.Manager.createPlayer(ds);
if (p ==null)
return;
p.addControllerListener(this);
p.realize();
PlayerWindow pw =new PlayerWindow(p, stream);
playerWindows.addElement(pw);
// Notify intialize() that a new stream had arrived.
synchronized (dataSync){
dataReceived =true;
dataSync.notifyAll();
}
}catch (Exception e){
System.err.println("NewReceiveStreamEvent exception " + e.getMessage());
return;
}
}
elseif (evtinstanceof StreamMappedEvent){
if (stream !=null && stream.getDataSource() !=null){
DataSource ds = stream.getDataSource();
// Find out the formats.
RTPControl ctl = (RTPControl)ds.getControl("javax.media.rtp.RTPControl");
System.err.println(" - The previously unidentified stream ");
if (ctl !=null)
System.err.println("" + ctl.getFormat());
System.err.println("had now been identified as sent by: " + participant.getCNAME());
}
}
elseif (evtinstanceof ByeEvent){
System.err.println(" - Got \"bye\" from: " + participant.getCNAME());
PlayerWindow pw = find(stream);
if (pw !=null){
pw.close();
playerWindows.removeElement(pw);
}
}
}
/**
* ControllerListener for the Players.
*/
publicsynchronizedvoid controllerUpdate(ControllerEvent ce){
Player p = (Player)ce.getSourceController();
if (p ==null)
return;
// Get this when the internal players are realized.
if (ceinstanceof RealizeCompleteEvent){
PlayerWindow pw = find(p);
if (pw ==null){
// Some strange happened.
System.err.println("Internal error!");
System.exit(-1);
}
pw.initialize();
pw.setVisible(true);
p.start();
}
if (ceinstanceof ControllerErrorEvent){
p.removeControllerListener(this);
PlayerWindow pw = find(p);
if (pw !=null){
pw.close();
playerWindows.removeElement(pw);
}
System.err.println("AVReceive2 internal error: " + ce);
}
}
/**
* A utility class to parse the session addresses.
*/
class SessionLabel{
public String addr =null;
publicint port;
publicint ttl = 1;
SessionLabel(String session)throws IllegalArgumentException{
int off;
String portStr = null, ttlStr =null;
if (session !=null && session.length() > 0){
while (session.length() > 1 && session.charAt(0) =='/')
session = session.substring(1);
// Now see if there's a addr specified.
off = session.indexOf('/');
if (off == -1){
if (!session.equals(""))
addr = session;
}else{
addr = session.substring(0, off);
session = session.substring(off + 1);
// Now see if there's a port specified
off = session.indexOf('/');
if (off == -1){
if (!session.equals(""))
portStr = session;
}else{
portStr = session.substring(0, off);
session = session.substring(off + 1);
// Now see if there's a ttl specified
off = session.indexOf('/');
if (off == -1){
if (!session.equals(""))
ttlStr = session;
}else{
ttlStr = session.substring(0, off);
}
}
}
}
if (addr ==null)
thrownew IllegalArgumentException();
if (portStr !=null){
try{
Integer integer = Integer.valueOf(portStr);
if (integer !=null)
port = integer.intValue();
}catch (Throwable t){
thrownew IllegalArgumentException();
}
}else
thrownew IllegalArgumentException();
if (ttlStr !=null){
try{
Integer integer = Integer.valueOf(ttlStr);
if (integer !=null)
ttl = integer.intValue();
}catch (Throwable t){
thrownew IllegalArgumentException();
}
}
}
}
/**
* GUI classes for the Player.
*/
class PlayerWindowextends Frame{
Player player;
ReceiveStream stream;
PlayerWindow(Player p, ReceiveStream strm){
player = p;
stream = strm;
}
publicvoid initialize(){
add(new PlayerPanel(player));
}
publicvoid close(){
player.close();
setVisible(false);
dispose();
}
publicvoid addNotify(){
super.addNotify();
pack();
}
}
/**
* GUI classes for the Player.
*/
class PlayerPanelextends Panel{
Component vc, cc;
PlayerPanel(Player p){
setLayout(new BorderLayout());
if ((vc = p.getVisualComponent()) !=null)
add("Center", vc);
if ((cc = p.getControlPanelComponent()) !=null)
add("South", cc);
}
public Dimension getPreferredSize(){
int w = 0, h = 0;
if (vc !=null){
Dimension size = vc.getPreferredSize();
w = size.width;
h = size.height;
}
if (cc !=null){
Dimension size = cc.getPreferredSize();
if (w == 0)
w = size.width;
h += size.height;
}
if (w < 160)
w = 160;
returnnew Dimension(w, h);
}
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JButton jButton5;
private javax.swing.JButton jButton6;
private javax.swing.JButton jButton7;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JPanel jPanel1;
private javax.swing.JProgressBar jProgressBar1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JSeparator jSeparator1;
private javax.swing.JSeparator jSeparator2;
private javax.swing.JSlider jSlider1;
private javax.swing.JTextArea jTextArea1;
private javax.swing.JTextArea jTextArea2;
// End of variables declaration//GEN-END:variables
private String ses[] ={"192.168.0.1/2222"};
}
remark: i dont put the received player window at my applet until now, am only recevig at window that initialized at the AVReceive window.
I wait the reply...

