myplayer.java

来自「this is the media streaming project」· Java 代码 · 共 71 行

JAVA
71
字号
/****************************************************************************************/
/* 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) */
/* MyPlayer.java: This class is responsible for the media player's generation		*/
/* Complile: javac MyPlayer.java							*/
/****************************************************************************************/

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

public class MyPlayer implements ControllerListener{
    Player player=null;
    DataSource ds=null;
    int type;
    StreamRecorder c;

    public MyPlayer(String _url, StreamRecorder _c, int _type) throws Exception{
    	c =_c;
        type=_type;
	MediaLocator locator=new MediaLocator(_url);
       	ds=Manager.createDataSource(locator);
	  	if (ds==null){
            System.err.println("Can not build DataSource for RTP");
	        System.exit(0);
	    }
    }

    public MyPlayer(DataSource _ds, StreamRecorder _c, int _type){
          ds=_ds;
          type=_type;
          c=_c;
    }

    public void start(){
	try{
	    player=Manager.createPlayer(ds);
	}
	catch (Exception e){
	    System.out.println(e);
	}

	player.addControllerListener(this);
	player.realize();
    }

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

    //add players to the interface at StreamRecorder
    public synchronized void controllerUpdate(ControllerEvent event){

      if (event instanceof RealizeCompleteEvent){
	Component comp;
	if ((comp=player.getVisualComponent())!=null){
	    c.addDisplay(type,comp);
	}
	if ((comp=player.getControlPanelComponent())!=null){
	    c.addDisplay(type,comp);
	    player.start();
	  
	}
      }
    }
}

⌨️ 快捷键说明

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