📄 iruapplet.java
字号:
return;
} else{
//get Controller
try{
Class [] classes1 = new Class[] {IRUControllerInterface.class};
ServiceTemplate template1 = new ServiceTemplate(null, classes1,null);
try {
Controller = (IRUControllerInterface) registrar.lookup(template1);
} catch(java.rmi.RemoteException e) {
e.printStackTrace();
}
if (Controller == null) {
System.out.println("Controller null");
return;
}else{
ControlPanel= new ControllerPanel (Controller);
SonarshowPanel=new SonarShowPanel(Controller);
}
}catch(Exception e){
e.printStackTrace();
}
}
}catch(Exception e){
e.printStackTrace();
}
//Setup MRWorldShowPanel and ControlPanel
}
public String getAddress(){
return address;
}
public int getPort(){
// the port has to be returned as an integer
return StrToInt(portstr);
}
private int StrToInt(String str){
if (str == null)
return -1;
Integer retint = new Integer(str);
return retint.intValue();
}
public synchronized void controllerUpdate(ControllerEvent event) {
Player player = null;
Controller controller = (Controller)event.getSource();
if (controller instanceof Player) player =(Player)event.getSource();
if (player == null) return;
if (event instanceof RealizeCompleteEvent) {
// add the video player's visual component to the applet
if (( visualComponent =
player.getVisualComponent())!= null){
width = visualComponent.getPreferredSize().width;
height += visualComponent.getPreferredSize().height;
if(Videopanel==null){
Videopanel=new Panel();
repositionPanel(width, height);
Videopanel.setLayout(new BorderLayout());
this.add(Videopanel ,new XYConstraints(0, 0, 320, 240));
Videopanel.setVisible(true);
}
Videopanel.add("Center", visualComponent);
Videopanel.validate();
}
// add the player's control component to the applet
if (( controlComponent =
player.getControlPanelComponent()) != null){
height += controlComponent.getPreferredSize().height;
if(Videopanel==null){
Videopanel=new Panel();
repositionPanel(width, height);
Videopanel.setLayout(new BorderLayout());
this.add(Videopanel ,new XYConstraints(0, 0, 320, 240));
Videopanel.setVisible(true);
}
repositionPanel(width, height);
Videopanel.add("South", controlComponent);
Videopanel.validate();
}
}
if (event instanceof SizeChangeEvent) {
if (Videopanel != null){
SizeChangeEvent sce = (SizeChangeEvent) event;
int nooWidth = sce.getWidth();
int nooHeight = sce.getHeight();
if (controlComponent != null)
nooHeight += controlComponent.getPreferredSize().height;
repositionPanel(nooWidth, nooHeight);
}
}
validate();
}
/**
* The video/control component panel needs to be repositioned to sit
* in the middle of the applet window.s
*/
void repositionPanel(int width, int height) {
Videopanel.setBounds(0,0,width,height);
Videopanel.validate();
}
public void update( ReceiveStreamEvent event){
RTPSessionMgr source =( RTPSessionMgr)event.getSource();
Player newplayer = null;
// create a new player if a new recvstream is detected
if (event instanceof NewReceiveStreamEvent){
try{
ReceiveStream stream = ((NewReceiveStreamEvent)event).getReceiveStream();
DataSource dsource = stream.getDataSource();
newplayer = Manager.createPlayer(dsource);
System.out.print("Receive New Stream.");
}catch (Exception e){
System.err.println("RTPPlayerApplet Exception " + e.getMessage());
e.printStackTrace();
}
if (newplayer == null){
System.out.print("New player is failed !");
return;
}else{
System.out.print("New player is ok !");
}
// if this is the first video player, we need to listen to
// its events. Add me as a ControllerListener before
// starting the player
if (source == videomgr){
System.out.print("Source = videomgr !");
if (videoplayer == null){
videoplayer = newplayer;
newplayer.addControllerListener(this);
newplayer.start();
}
else{// controller listener and start is taken care of
// in playerWindiow
if (playerlist != null)
playerlist.addElement((Object)newplayer);
new PlayerWindow(newplayer);
}
}// if (source == videomgr)
}// if (event instanceof NewReceiveStreamEvent)
}// end of RTPSessionUpdate
private RTPSessionMgr StartSessionManager(String destaddrstr,
int port){
RTPSessionMgr mymgr = new RTPSessionMgr();
videomgr=mymgr;
if (mymgr == null) return null;
mymgr.addReceiveStreamListener(this);
String cname = mymgr.generateCNAME();
String username = "jmf-user";
SessionAddress localaddr = new SessionAddress();
// SessionAddress localaddr = null;
try{
destaddr = InetAddress.getByName(destaddrstr);
}catch (UnknownHostException e){
System.err.println("inetaddress " + e.getMessage());
e.printStackTrace();
}
SessionAddress sessaddr = new SessionAddress(destaddr,port);
SourceDescription[] userdesclist = new SourceDescription[4];
int i;
for(i=0; i< userdesclist.length;i++){
if (i == 0){
userdesclist[i] = new SourceDescription(SourceDescription.SOURCE_DESC_EMAIL,"jmf-user@sun.com", 1,false);
continue;
}
if (i == 1){
userdesclist[i] = new SourceDescription(SourceDescription.SOURCE_DESC_NAME,username,1, false);
continue;
}
if ( i == 2){
userdesclist[i] = new SourceDescription(SourceDescription.SOURCE_DESC_CNAME, cname,1, false);
continue;
}
if (i == 3){
userdesclist[i] = new SourceDescription(SourceDescription.SOURCE_DESC_TOOL,"JMF RTP Player v2.0", 1,false);
continue;
}
}// end of for
try{
mymgr.initSession(localaddr,mymgr.generateSSRC(), userdesclist, 0.05, 0.25);
mymgr.startSession(sessaddr,1,null);
}catch (SessionManagerException e){
System.err.println("RTPPlayerApplet: RTPSM Exception " + e.getMessage());
e.printStackTrace();
return null;
}catch (IOException e){
System.err.println("RTPPlayerApplet: IO Exception " + e.getMessage());
e.printStackTrace();
return null;
}
return mymgr;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -