Java在线视频聊天(2)
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.getControlPanelComponent())!=null)
//player.getControlPanelComponent()是显示时间的组件
{
p4.add(comVC,"South");
}
}
catch (Exception e)
{
e.printStackTrace();
}
setBounds(200,100,600, 550);
setVisible(true);
int new_w= p4.getWidth(); //输出的图像宽度
int new_h= p4.getHeight(); //输出的图像高度
//MediaTracker类跟踪一个Image对象的装载,完成图像加载
MediaTracker mt = new MediaTracker(this.p4);
try
{
mt.addImage(image, 0);//装载图像
mt.waitForID(0);//等待图像全部装载
}
catch (Exception e)
{
e.printStackTrace();
}
//将图像信息写入缓冲区
BufferedImage buffImg = new BufferedImage(new_w, new_h,BufferedImage.TYPE_INT_RGB);
Graphics g = buffImg.createGraphics();
g.drawImage(image, 0, 0, new_w, new_h, this.p4);
g.dispose();
}
//在本地播放音频
private void speaker() throws Exception
{
Vector deviceList = CaptureDeviceManager.getDeviceList(new
AudioFormat(AudioFormat.LINEAR,44100,16,2));
if(deviceList.size()>0)
{
device2 = (CaptureDeviceInfo)deviceList.firstElement();
}
else
{
System.out.println("找不到音频设备!");
}
try
{
player2 = Manager.createRealizedPlayer(device2.getLocator());
player2.start();
if((comA = player2.getControlPanelComponent())!=null)
{
p3.add(comA,"South");
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
//线程,接收或发送视频图像数据
public void run()
{
DatagramPacket pack=null;
DatagramSocket maildata=null;
byte data[]=new byte[320*240];
try
{
//定义数据包
pack=new DatagramPacket(data,data.length);
//定义数据报接收包
maildata=new DatagramSocket(999);
}
catch(Exception e){ }
while(true)
{
if(Thread.currentThread()==thread1)
{
if(maildata==null)
{
break;
}
else
{
try
{
相关新闻>>
- 发表评论
-
- 最新评论 更多>>