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

📄 multimediasynchronization.java

📁 java同步播放工具
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package MultimediaSynchronization; 
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.media.*;
import java.net.URL;

public class MultimediaSynchronization{
	Panel panel_video = null;    
	Player videoPlayer = null;
    Component visualComponent_video = null;
    Component controlComponent_video = null;
    int controlPanelHeight_video = 0;
    int videoWidth = 0;
    int videoHeight = 0;
        	
	Player audioPlayer = null;
       
	JFrame f;
	JLabel audioLable,image1,image2,image1Lable,image2Lable;
	Panel panel_image1=null;
	Panel panel_image2=null;
	JTextArea AreaOfTxt;
	URL mediaURL_video,mediaURL_audio;
	JButton begin,b_video,b_audio,help;
	JButton b_openImage1,b_openImage2,stopit;
	FileDialog file_video,file_audio,file_image1,file_image2;

	
	public MultimediaSynchronization(){
		f=new JFrame("011685_群星为反sars义唱:手牵手!");
		
			try {
	    UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
	} catch (Exception e) {
	    System.err.println("Could not initialize java.awt Metal lnf");
	}
	f.addWindowListener( new WindowAdapter() {public void windowClosing(WindowEvent we) {System.exit(0);}} );
	    
	    panel_video=new Panel();	    
	    panel_video.setLayout(null);
	    b_video=new JButton("添加视频");	    
	    b_audio=new JButton("添加音频");	    
	    image1Lable=new JLabel("图像1");
	    image2Lable=new JLabel("图像2");
	    
	    try{
	    mediaURL_video=new URL(null);
	    mediaURL_audio=new URL(null);
	    mediaURL_video=null;
	    mediaURL_audio=null;
	    }catch(Exception e){}

	    AreaOfTxt=new JTextArea();	    
	    JScrollPane jsp=new JScrollPane(AreaOfTxt); 
	    AreaOfTxt.setText("使用须知:\n");
		AreaOfTxt.append("本实验实现的是基于事件的同步\n");
		AreaOfTxt.append("同步时间与实验给的初步情况一致\n");
		AreaOfTxt.append("使用方法:\n");
		AreaOfTxt.append("分别点击'添加视频''添加音频''打开图像1''打开图像2'加入需要打开的文件\n");
		AreaOfTxt.append("点击‘开始‘即可以进行演示\n");
			
		
		help=new JButton("帮助");
		

	    panel_image1=new Panel();
	    panel_image2=new Panel();
	    image1=new JLabel("");
	    image2=new JLabel("");
	    panel_image1.add(image1);
	    panel_image1.setBackground(Color.orange);
	    
	    panel_image2.add(image2);
	    panel_image2.setBackground(Color.orange);
	    b_openImage1=new JButton("打开图像1");
        b_openImage2=new JButton("打开图像2");
        
        begin =new JButton("开始");          
        stopit=new JButton("结束");


		f.getContentPane().setBackground(Color.orange);
        f.getContentPane().setLayout(null);	        
	    f.getContentPane().add(panel_video);
	    f.getContentPane().add(image1Lable);
	    f.getContentPane().add(image2Lable);	    
	    f.getContentPane().add(panel_image1);
	    f.getContentPane().add(panel_image2);
	    f.getContentPane().add(b_openImage1);
	    f.getContentPane().add(b_openImage2);
        f.getContentPane().add(begin);
        f.getContentPane().add(stopit);
        f.getContentPane().add(b_video);
        f.getContentPane().add(b_audio);
        f.getContentPane().add(jsp);
        f.getContentPane().add(help);
	    f.setSize(670,560);
	    //f.setBackground(Color.blue);
	    b_video.setBounds(0,0,100,30);
	    b_video.setBackground(Color.orange);
        b_audio.setBounds(100,0,100,30);
        b_audio.setBackground(Color.orange);
        b_openImage1.setBounds(200,0,100,30);
        b_openImage1.setBackground(Color.orange);
        b_openImage2.setBounds(300,0,100,30);
        b_openImage2.setBackground(Color.orange);
        help.setBounds(570,0,100,30);
        help.setBackground(Color.orange);
        begin.setBounds(45,500,80,30);
        begin.setBackground(Color.orange);
        stopit.setBounds(225,500,80,30);
        stopit.setBackground(Color.orange);
        panel_image1.setBounds(360,65,300,215);
	    panel_image2.setBounds(360,305,300,215);
		jsp.setBounds(0,350,355,145);        
	    image1Lable.setBounds(480,40,100,30);
	    image2Lable.setBounds(480,285,100,30);
        f.setVisible(true);   
        panel_image1.setVisible(true);
        panel_image1.setBackground(Color.orange);
        panel_image2.setVisible(true);
        panel_image2.setBackground(Color.orange);
          

		L_Help l_help;
		help.addActionListener(l_help=new L_Help());
		  
        L_Start l_Start;
        begin.addActionListener(l_Start=new L_Start());
             
        L_openVideoFile l_openVideo;
        b_video.addActionListener(l_openVideo=new L_openVideoFile());
        
        L_openAudioFile l_openAudio;
        b_audio.addActionListener(l_openAudio=new L_openAudioFile());
        
        L_Image1 l_image1;
        b_openImage1.addActionListener(l_image1=new L_Image1());
        
        L_Image2 l_image2;
        b_openImage2.addActionListener(l_image2=new L_Image2());
        
        L_Stop l_stop ;
        stopit.addActionListener(l_stop=new L_Stop());
   	}
	
 
	public void videoStart() {
	    if(file_video==null || file_video.getDirectory()==null)
		{
			      visualComponent_video = null;
                  controlComponent_video = null;
                  controlPanelHeight_video = 0;
                  videoWidth = 0;
                  videoHeight = 0;
		        try{                   
		          URL mediaURL=new URL("file:///C://java//ok_all.mpg");
		          videoPlayer=Manager.createPlayer(mediaURL);
		          L_openVideoFile l_openVideoFile =new L_openVideoFile();
		      	  videoPlayer.addControllerListener(l_openVideoFile);
		        }catch(Exception e){}
        }
        if(mediaURL_video!=null)
        {
        	 visualComponent_video = null;
             controlComponent_video = null;
             controlPanelHeight_video = 0;
             videoWidth = 0;
             videoHeight = 0;
        	try{                   
		          videoPlayer=Manager.createPlayer(mediaURL_video);
		          L_openVideoFile l_openVideoFile =new L_openVideoFile();
		      	  videoPlayer.addControllerListener(l_openVideoFile);
		        }catch(Exception e){}
        }
        if (videoPlayer != null)
            videoPlayer.start();
    }
    public void videoStop() {        
        if (videoPlayer != null) {
            videoPlayer.stop();
            videoPlayer.deallocate();
        }
    }

    public void videoDestroy() {
    	if (videoPlayer != null) {
        videoPlayer.close();
        visualComponent_video = null;
        controlComponent_video = null;
        controlPanelHeight_video = 0;
        videoWidth = 0;
        videoHeight = 0;
        }
    }
    class L_openVideoFile implements ActionListener,ControllerListener{       
		public void actionPerformed(ActionEvent e)
		{		videoDestroy();
			  file_video=new FileDialog(f,"open Video File",FileDialog.LOAD);
              file_video.show(true);                        

              try{
				
		          URL mediaURL=new URL("file:///"+file_video.getDirectory()+
		          file_video.getFile());
		          if(file_video.getDirectory()!=null)
		          {
		          	mediaURL_video=mediaURL;
		          }
		          videoPlayer=Manager.createPlayer(mediaURL);
		      	  videoPlayer.addControllerListener(this);

		   	  }catch(Exception ee){
		   		  }
		}		
		public synchronized void controllerUpdate(ControllerEvent event) {		
            if (videoPlayer == null)
                return;          
            if (event instanceof RealizeCompleteEvent) {               
                int width = 0;
                int height = 0;

⌨️ 快捷键说明

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