⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 streamrecorder.java

📁 this is the media streaming project
💻 JAVA
字号:
/****************************************************************************************/
/* 2001-Spring: Java Network-Programming Term-Project					*/
/* Title: Streaming media generation, capture and store.				*/
/* Team Member: Yumin Yuan(yuany@rpi.edu), Rui Mu(mur@rpi.edu), Yining Hu(huyn@rpi.edu) */
/* StreamRecorder.java: This class is responsible for the interface and function of   	*/
/* real-time communication. It will be called by StreamStarter and will call MyPlayer 	*/	
/* and other media classes to do the real-time play and send. It also can capture and 	*/
/* and save the streaming media.							*/
/* Complile: javac StreamRecorder.java							*/
/****************************************************************************************/

import javax.media.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;

public class StreamRecorder extends JFrame{
    public static final int SEND=0;
    public static final int RECEIVE=1;
    private static DSFactory factory=null;

    VideoTransmit vt=null;
    Recorder recorder=null;
    MyPlayer lvideoPlayer,rvideoPlayer;
    JPanel receivepanel,sendPanel;

    //interface generation for real-time communications
    public StreamRecorder(String ip, String sendPort, String receivePort, String data){
	super("Stream Sender, Player and Recorder");
	Manager.setHint(Manager.LIGHTWEIGHT_RENDERER,new Boolean(true));
	 
    	Container c=getContentPane();
    	c.setLayout(new BoxLayout(c,BoxLayout.Y_AXIS));

	receivepanel=new JPanel();
    	receivepanel.setLayout(new BoxLayout(receivepanel,BoxLayout.Y_AXIS));
	receivepanel.setBorder(BorderFactory.createEtchedBorder());
	sendPanel=new JPanel();
    	sendPanel.setLayout(new BoxLayout(sendPanel,BoxLayout.Y_AXIS));
	sendPanel.setBorder(BorderFactory.createEtchedBorder());
	JPanel controlPanel=new JPanel();
    	controlPanel.setLayout(new BoxLayout(controlPanel,BoxLayout.X_AXIS));
	controlPanel.setBorder(BorderFactory.createEtchedBorder());
	controlPanel.add(receivepanel);
    	controlPanel.add(sendPanel);
	
	JButton startButton=new JButton("Start to save");
	startButton.addActionListener(new StartRecord());

	JButton stopButton=new JButton("Stop saving");
	stopButton.addActionListener(new StopRecord());

	JButton quitButton=new JButton("Quit");
    	quitButton.addActionListener(new exitProcess());
	JPanel buttonPanel=new JPanel();
	buttonPanel.setLayout(new BoxLayout(buttonPanel,BoxLayout.X_AXIS));
	buttonPanel.setBorder(BorderFactory.createEtchedBorder());
	buttonPanel.add(startButton);
	buttonPanel.add(stopButton);
	buttonPanel.add(quitButton);
		    	
	c.add(controlPanel);
    	c.add(buttonPanel);
	factory=new DSFactory(ip, sendPort, receivePort, data);//create data source
    }
    //interface generation for timing-recording function
    public StreamRecorder(String ip, String receivePort){
	super("Timing Recorder");
	Manager.setHint(Manager.LIGHTWEIGHT_RENDERER,new Boolean(true));
	 
    	Container c=getContentPane();
    	c.setLayout(new BoxLayout(c,BoxLayout.Y_AXIS));

	receivepanel=new JPanel();
    	receivepanel.setLayout(new BoxLayout(receivepanel,BoxLayout.Y_AXIS));
	receivepanel.setBorder(BorderFactory.createEtchedBorder());

	JPanel controlPanel=new JPanel();
    	controlPanel.setLayout(new BoxLayout(controlPanel,BoxLayout.X_AXIS));
	controlPanel.setBorder(BorderFactory.createEtchedBorder());
	controlPanel.add(receivepanel);
	
	JLabel timing=new JLabel("Timing Recording");

	JPanel labelPanel=new JPanel();

	labelPanel.add(timing);
		    	
	c.add(controlPanel);
    	c.add(labelPanel);
	factory=new DSFactory(ip, receivePort);
    }


    public void send(){

      // Create a video transmit object with the specified params.
      try{
	MyPlayer lvideoPlayer=new MyPlayer(factory.getLocalCloneVideoDS(),this,StreamRecorder.SEND);
   	lvideoPlayer.start();

	vt = new VideoTransmit(factory.getSendVideoURL(),factory.getLocalCloneVideoDS());
        String vresult = vt.start();
     
      }catch (Exception e){}
    }

    //recieving streaming video
    public void receive(){

	try{
	    factory.createRemote();

	    rvideoPlayer=new MyPlayer(factory.getRemoteVideoDS(),this,StreamRecorder.RECEIVE);
	    rvideoPlayer.start();

	}
	catch (Exception e){
	    System.out.println(e);
	}
    }

    //add Player picture to interface
    public void addDisplay(int type,Component com){
	if (type==StreamRecorder.RECEIVE)
	    receivepanel.add(com);
	else
	    sendPanel.add(com);
	validate();
    }
    
    public DSFactory getDSF(){ return factory;}

    class exitProcess implements ActionListener{
	public void actionPerformed(ActionEvent e){

          if (lvideoPlayer!=null)
            lvideoPlayer.stop();

          if (rvideoPlayer!=null)
            rvideoPlayer.stop();

          if (vt!=null)
	    vt.stop();

          setVisible(false);
	  dispose();
	}
    }

    //start saving the streaming media
    class StartRecord implements ActionListener{
	public void actionPerformed(ActionEvent e){
	    final JFileChooser fc = new JFileChooser();
	     
	    int returnVal = fc.showSaveDialog(StreamRecorder.this);

	    if (returnVal == JFileChooser.APPROVE_OPTION) {
		File file = fc.getSelectedFile();
		System.out.println(file.getAbsolutePath());
		recorder=new Recorder(file.getAbsolutePath());
		recorder.prepareVideo(factory.getRemoteVideoDS());
		recorder.start();
	    } 
	}
    }

     class StopRecord implements ActionListener{
	public void actionPerformed(ActionEvent e){
	    recorder.stop();
	}
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -