java swing下的MJPG-Streamer客户端

   MJPG-Streamer客户端的关键是读取JPG文件。

  JPG文件 头标识 0xff 0xd8  尾标识 0xff 0xd9

  把中间取出来放到JLabel中就是视频。

@Override

    public void run() {

       byte[] ca = new byte[128*1024];
       byte[] cab = new byte[328 * 1024];

        URL ur;
        int i=0;
        int status=0;
        int cabindex=0;
        int js=0,jss=0,jj=0;
        try {
          //  ur = new URL("http://192.168.3.16:8082/?action=stream");
          ur= new URL("http://192.168.0.102:8080/?action=stream");
            URLConnection uc = ur.openConnection();
            uc.connect();
            InputStream is=uc.getInputStream();
             BufferedOutputStream bw = new BufferedOutputStream(new FileOutputStream(new File("D:\\NetBeansProjects\\JavaApplication1\\src\\tcp\\N.jp")));
            while((jj=is.read(ca))!=-1){
              //  ll.setText(String.valueOf(is.()));
                for(i=0;i<jj;i++){
                    if(ca[i]==(byte)0xff){
                        if(ca[i+1]==(byte)0xd8){
                         status=1;
                        jss++;
                        ll.setText(String.valueOf(jss));
                    }
                    }
                   if(status==1){
                       cab[cabindex]=ca[i];
                       cabindex++;
                       if(i!=0){
                     if(ca[i-1]==(byte)0xff){
                       if(ca[i]==(byte)0xd9){
                           ll2.setText(String.valueOf(js));
                           status=0;
                           cabindex=0;
                           js++;
                           ll.setIcon(new javax.swing.ImageIcon(cab));
                   }  
                     }
                       }
                   }
                }
             
             
        }
        } catch (MalformedURLException ex) {
            Logger.getLogger(vedio.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(vedio.class.getName()).log(Level.SEVERE, null, ex);
        }

        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值