Java在线视频聊天
来源:技术人生 责任编辑:栏目编辑 发表时间:2013-07-01 05:32 点击:次
Java在线视频聊天
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import java.util.*;
import java.io.*;
import java.net.*;
import javax.imageio.*;
import javax.swing.*;
import javax.media.*;
import javax.media.protocol.*;
import javax.media.control.*;
import javax.media.util.*;
import javax.media.format.*;
import com.sun.image.codec.jpeg.*;
class VAplay extends JFrame implements Runnable
{
//定义视频图像播放器
private static Player player = null;
//定义音频播放器
private static Player player2 = null;
//获取视频设备
private CaptureDeviceInfo device = null;
//获取音频设备
private CaptureDeviceInfo device2 = null;
//媒体定位器
private MediaLocator locator = null;
private Image image;
private Buffer buffer = null;
private BufferToImage b2i = null;
//设置摄像头驱动类型
String str = "vfw:Microsoft WDM Image Capture (Win32):0";
//定义播放组件变量
Component comV,comVC,comA;
//定义面板
JPanel p1,p2,p3,p4;
JLabel label=new JLabel("对方IP:");
//初始时,在接收图像窗口显示一幅静态图片
JLabel label2=new JLabel(new ImageIcon("image//load.gif"));
//定义二个线程,用于接收数据和发送数据
Thread thread1,thread2;
VAplay()
{
super("视频传输");
setBounds(150,100,500,500);
p1=new JPanel(new GridLayout(1,2));
p2=new JPanel(new GridLayout(2,1));
p3=new JPanel(new BorderLayout());
p4=new JPanel(new BorderLayout());
//加载文本数据传输类
p1.add(new TxtChat());
p1.add(p2);
p2.add(p3);
p2.add(p4);
p3.add("North",new JLabel("Java视频图像传输"));
p3.add(label2,"Center");
add(label,"North");
add(p1,"Center");
try
{
//在本地播放视频
jbInit();
//在本地播放音频
speaker();
}
catch(Exception e)
{
e.printStackTrace();
}
thread1=new Thread(this);
thread2=new Thread(this);
//负责接收对方数据
thread1.start();
//负责向对方发送数据
thread2.start();
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
setVisible(true);
validate();
}
//在本地播放视频
private void jbInit() throws Exception
{
//初始化设备,真人视频,str为设备驱动
device = CaptureDeviceManager.getDevice(str);
//确定所需的协议和媒体资源的位置
locator = device.getLocator();
try
{
//调用sethint后Manager会尽力用一个能和轻量级组件混合使用的Renderer来创建播放器
Manager.setHint(Manager.LIGHTWEIGHT_RENDERER,new Boolean(true));
//通过管理器创建播放线程使player达到Realized状态
player = Manager.createRealizedPlayer(locator);
player.start();
if((comV = player.getVisualComponent()) != null)
//player.getVisualComponent()是一个播放视频媒体组件。
{
p4.add(comV,"Center");
}
if((comVC=player.getControlPanelCompone
相关新闻>>
- 发表评论
-
- 最新评论 更多>>