Tuesday, June 10, 2014

Creating an Embedded Video Streaming Server in Android

Different video streaming server provides different capabilities for streaming videos. What to do if you want to stream something inside your Android application.

Here is how you can create a simple streaming server:

NanoHttpd is an open-source, small-footprint web server that is suitable for embedding in Java applications. The code consists of single Java application file which can be used as a 
streaming server. Following is how to create using Android code:

public class VideoStreamingServer extends NanoHTTPD {

    public VideoStreamingServer() {
         // by default listening on port 8080

    public Response serve(String URI, Method method,
        Map header, Map parameters,
        Map files) {

    FileInputStream fis = null;
    try {
        fis = new FileInputStream(EXTERNAL_STORAGE_FILE_LOCATION);
    } catch (FileNotFoundException e) {
    return new NanoHTTPD.Response(Status.OK, "video/mp4", fis);

No comments: