qq_34316891 2017-04-17 13:43 采纳率: 100%
浏览 1084

手机实时传输的视频不能播放

class Send implements Runnable {
Socket socket = null;
OutputStream os = null;
File file = null;
FileInputStream fis = null;
byte[] bytes;
boolean flag = true;
DataOutputStream dos=null;
Send(File file) {
this.file = file;
}

public void connect() {
    try {
        socket = new Socket("192.168.1.100", 9991);
        os = socket.getOutputStream();
        dos = new DataOutputStream(os);
        fis=   new FileInputStream(file);
        String a = file.getAbsolutePath();


    } catch (IOException e) {
    }
    bytes = new byte[1024];
    int length=0;
    try {
        while(true&flag){
            while ((length = fis.read(bytes, 0, bytes.length))> 0) {
                dos.write(bytes, 0, length);
                dos.flush();
            }
            try {
                new Thread().sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    finally{
        if(fis!=null){
            try {
                fis.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        if(dos!=null){
            try {
                dos.flush();
                dos.close();
            } catch (IOException e) {
                e.printStackTrace();
            }

        }
    }
}

public void run() {
    connect();
}

}
上面的是android端的程序这个就是实时传输视频的程序,但是传输到PC端的视频无法播放,请问哪一位大神能给我解决一下,很急

下面的是PC端服务器接受视频的数据
import java.io.BufferedOutputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class bbbb{
public static void main(String[] args){
try {
ServerSocket ss=new ServerSocket(9991);
Socket socket=ss.accept();
System.out.print("hh");
new Thread(new oo(socket)).start();
} catch (IOException e) {
e.printStackTrace();
}
}
}

class oo implements Runnable{
int length;
Socket socket;
DataInputStream dis;
FileOutputStream fos;
oo(Socket socket){
this.socket=socket;
}
public void run() {
try {
dis=new DataInputStream(socket.getInputStream());
fos=new FileOutputStream(new File("C:/Users/lenovo/Desktop/gg1/a.mp4"));
byte[] bytes=new byte[1024];

        while((length=dis.read(bytes,0,bytes.length))>0){
            fos.write(bytes, 0, length);
            fos.flush();
            try {
                new Thread().sleep(1);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }



    } catch (IOException e) {
        e.printStackTrace();
    }
    finally{
        if(fos!=null){      
            try {
                fos.flush();
                fos.close();
                System.out.print("接收完毕!");
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

}

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-04-17 15:49
    关注

    首先检查下网络连接,用抓包工具看下

    评论

报告相同问题?

悬赏问题

  • ¥20 删除和修改功能无法调用
  • ¥15 kafka topic 所有分副本数修改
  • ¥15 小程序中fit格式等运动数据文件怎样实现可视化?(包含心率信息))
  • ¥15 如何利用mmdetection3d中的get_flops.py文件计算fcos3d方法的flops?
  • ¥40 串口调试助手打开串口后,keil5的代码就停止了
  • ¥15 电脑最近经常蓝屏,求大家看看哪的问题
  • ¥60 高价有偿求java辅导。工程量较大,价格你定,联系确定辅导后将采纳你的答案。希望能给出完整详细代码,并能解释回答我关于代码的疑问疑问,代码要求如下,联系我会发文档
  • ¥50 C++五子棋AI程序编写
  • ¥30 求安卓设备利用一个typeC接口,同时实现向pc一边投屏一边上传数据的解决方案。
  • ¥15 SQL Server analysis services 服务安装失败