📄 rtpplayerapplet.java
字号:
/* * @(#)RTPPlayerApplet.java 1.3 01/03/13 * * Copyright (c) 1999-2001 Sun Microsystems, Inc. All Rights Reserved. * * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use, * modify and redistribute this software in source and binary code form, * provided that i) this copyright notice and license appear on all copies of * the software; and ii) Licensee does not utilize the software in a manner * which is disparaging to Sun. * * This software is provided "AS IS," without a warranty of any kind. ALL * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE * POSSIBILITY OF SUCH DAMAGES. * * This software is not designed or intended for use in on-line control of * aircraft, air traffic, aircraft navigation or aircraft communications; or in * the design, construction, operation or maintenance of any nuclear * facility. Licensee represents and warrants that it will not use or * redistribute the Software for such purposes. */import java.applet.Applet;import javax.media.rtp.*;import javax.media.rtp.rtcp.*;import javax.media.rtp.event.*;import com.sun.media.rtp.RTPSessionMgr;import java.io.*;import java.awt.*;import java.util.Vector;import java.net.*;import java.awt.event.*;import java.lang.String;import javax.media.*;import javax.media.protocol.*;import com.sun.media.*;import com.sun.media.ui.*;import java.io.IOException;import java.lang.SecurityException;import rtp.*;// This RTP applet will allow a user to playback streams for one audio// session and one video session. Video and Audio RTP monitors are// also available for displaying RTCP statistics of this// session.Methods// StartSessionManager() will take care of starting the session and// registering this applet as an RTP Session Listener.// Method RTPSessionUpdate() will process all the RTPEvents sent by// the SessionManager.public class RTPPlayerApplet extends Applet implementsControllerListener, ReceiveStreamListener, ActionListener{ InetAddress destaddr; String address; String portstr; String media; Player videoplayer = null; SessionManager videomgr = null; SessionManager audiomgr = null; Component visualComponent = null; Component controlComponent = null; Panel panel = null; Button audiobutton = null; Button videobutton = null; GridBagLayout gridbag = null; GridBagConstraints c = null; ParticipantListWindow videogui = null; ParticipantListWindow audiogui = null; int width = 320; int height =0; Vector playerlist = new Vector(); public void init(){ setLayout( new BorderLayout() ); Panel buttonPanel = new Panel(); buttonPanel.setLayout( new FlowLayout() ); add("North", buttonPanel); media = getParameter("video"); if (media.equals("On")){ address = getParameter("videosession"); portstr = getParameter("videoport"); StartSessionManager(address, StrToInt(portstr), "video"); if (videomgr == null){ System.err.println("null video manager "); return; } // this is the GUI for displaying the RTCP // statistics. This will not be displayed until the user // clicks on the RTP Monitor window //videogui = new ParticipantListWindow(videomgr); // add a button for the video RTP monitor videobutton = new Button("Video RTP Monitor"); videobutton.addActionListener(this); buttonPanel.add(videobutton); } media = getParameter("audio"); if (media.equals("On")){ address = getParameter("audiosession"); portstr = getParameter("audioport"); StartSessionManager(address, StrToInt(portstr), "audio"); if (audiomgr == null){ System.err.println("null audio manager"); return; } //audiogui = new ParticipantListWindow(audiomgr); // add a button for the audio RTP monitor audiobutton = new Button("Audio RTP Monitor"); audiobutton.addActionListener(this); buttonPanel.add(audiobutton); } }// end of constructor public void start(){ // The applet only controls the first video player by adding // its visual and control component to the applet canvas. Thus // only this player needs to be controlled when this applet is // swiched in browser pages etc. if (videoplayer != null){ videoplayer.start(); } if (playerlist == null) return; for (int i =0; i < playerlist.size(); i++){ Player player = (Player)playerlist.elementAt(i); if (player != null) new PlayerWindow(player); } } // applet has been stopped, stop and deallocate all the RTP players. public void stop(){ if (videoplayer != null){ videoplayer.close(); } if (playerlist == null) return; for (int i =0; i < playerlist.size(); i++){ Player player = (Player)playerlist.elementAt(i); if (player != null){ player.close(); } } } // applet has been destroyed by the browser. Close the Session // Manager. public void destroy(){ // close the video and audio RTP SessionManagers String reason = "Shutdown RTP Player"; if (videomgr != null){ videomgr.closeSession(reason); videoplayer = null; videomgr = null; } if (audiomgr != null){ audiomgr.closeSession(reason); audiomgr = null; } super.destroy(); } public void actionPerformed(ActionEvent event){ Button button = (Button)event.getSource(); if ((button == videobutton) && (videomgr != null)) videogui = new ParticipantListWindow(videomgr); //videogui.Show(); if ((button == audiobutton) && (audiomgr != null)) audiogui = new ParticipantListWindow(audiomgr); //audiogui.Show(); } public String getAddress(){ return address; } public int getPort(){ // the port has to be returned as an integer return StrToInt(portstr); } public String getMedia(){ return media; } 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();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -