2013年8月21日星期三

android video ?

 This post last edited by the kaly_liu on 2013-08-13 15:23:29
Android client is the use of socket camera data transmission , on another android device how to receive and play ?

Socket tempSocket = new Socket(ipname, port);
                outsocket = tempSocket.getOutputStream();
                //写入头部数据信息
            String msg=java.net.URLEncoder.encode("PHONEVIDEO|"+username+"|","utf-8");
                byte[] buffer= msg.getBytes();
                outsocket.write(buffer);
                //将数据转成 数据流
                ByteArrayInputStream inputstream = new ByteArrayInputStream(myoutputstream.toByteArray());
                int amount;
                //在while括号里面 读取数据的个数 amount
                while ((amount = inputstream.read(byteBuffer)) != -1) {
                    outsocket.write(byteBuffer, 0, amount);//将 byteBuffer里的数据发送出去 ,一共有amount个
                }
                myoutputstream.flush();
                myoutputstream.close();
                tempSocket.close();          



if(data!=null)
      {
        YuvImage image = new YuvImage(data,VideoFormatIndex, VideoWidth, VideoHeight,null);
        if(image!=null)
        {
        ByteArrayOutputStream outstream = new ByteArrayOutputStream();
        //在此设置图片的尺寸和质量
        image.compressToJpeg(new Rect(0, 0, (int)(VideoWidthRatio*VideoWidth),
        (int)(VideoHeightRatio*VideoHeight)), VideoQuality, outstream); 
        outstream.flush();
        //启用线程将图像数据发送出去
        Thread th = new MySendFileThread(outstream,pUsername,serverUrl,serverPort);
        th.start(); 
        }

these two codes is part of the program the sender .
------ Solution ---------------------------------------- ----
socket too unstable , the landlord can do a set ?
------ Solution ---------------------------------------- ----
you are sending a jpeg types of data , I think you should define a tcp based on proprietary protocols, such as the first four bytes are the length jpeg , jpeg then followed by the actual data, and then received the first four bytes of the receiver to get the length , then the length of bytes received , and then converted to a bitmap in jpeg ImageView above show it. If it is video, then not so simple , requires both sides to negotiate video formats
------ Solution ------------------------- -------------------
generally use the RTP protocol packets issued
------ reference ----------- ----------------------------

anyway, you can send the data , the receiver did not get , do not know how effective amount · · Haha

没有评论:

发表评论