我们如何用http来播放Android的实时视频

时间:2017-03-31 06:47:18

标签: android

我尝试过使用libstreaming库并使用rtsp成功直播并在vlc播放器中播放但是我无法使用http进行流式传输以便我可以将我的视频流广播到我自己的服务器,有什么办法可以做那个?

我要求从Android应用程序广播实时视频,也可以从其他Android设备查看。

1 个答案:

答案 0 :(得分:0)

我认为你以错误的方式得到它,你不向你发送(上传)和服务器广播的服务器广播。广播同时向所有连接的客户端发送相同的数据。客户端不广播服务器的数据。你也可以在Android上设置一个http服务器,但由于你已经有一个单独的服务器,我认为这不是你想要的。

所以,如果它是带UDP的java情况,那么start就是这样的:

UDPServer.java:
import java.io.*;
import java.net.*;

class UDPServer
{
    public static void main(String args[]) throws Exception
    {
        DatagramSocket serverSocket = new DatagramSocket(PORT);
        byte[] receiveData = new byte[FRAMESIZE];
        while(true)
        {
            DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
            serverSocket.receive(receivePacket);
            // IP and port of the client who sent you this
            // in case of some type of feedback since UDP doesn't do that
            //InetAddress IPAddress = receivePacket.getAddress();
            //int port = receivePacket.getPort();

            // store data somewhere sharable lock it before store it
        }
    }
}

UDPClient.java:
import java.io.*;
import java.net.*;

class UDPClient
{
    public static void main(String args[]) throws Exception
    {
        BufferedReader inFromUser =
        new BufferedReader(new InputStreamReader(System.in));
        DatagramSocket clientSocket = new DatagramSocket();
        InetAddress IPAddress = InetAddress.getByName("localhost");
        byte[] sendData = new byte[FRAMESIZE];
        /* WebCam Frame Capture Code*/
        // but you should do it continuously on your frame capture event
        DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, PORT);
        clientSocket.send(sendPacket);

        clientSocket.close();
    }
}

这里有一些参考文献:

http://android-er.blogspot.com/2016/05/android-datagramudp-client-example.html http://www.helloandroid.com/tutorials/simple-udp-communication-example https://www.digi.com/wiki/developer/index.php/Android_UDP_Client

http://www.androidhive.info/2014/06/android-streaming-live-camera-video-to-web-page/

通过一些修改,我认为这就是你想要的:

http://code.google.com/p/spydroid-ipcamera /