Sidhanth Sur
Sidhanth Sur

Reputation: 303

Setting CORS for NanoHttpd in android

I have a hls stream that is downloaded from server. I then create a local webserver using this library ! I successfully ran the server and I can play the content from a VLC player on my PC .However it fails on JW player and Google Chromecast due to CORS issue. The possible solutions I found is to put a .htaccess file / crossdomain.xml file in the folder my server runs from . Is there a way to programatically set the headers of NanoHttpd to allow CORS ? This I am using to locally serve files to the google Chromecast

Upvotes: 5

Views: 2036

Answers (1)

Mahesh Giri
Mahesh Giri

Reputation: 1840

  resp= newFixedLengthResponse(Response.Status.OK, MIME_PLAINTEXT ,"success");
            resp.addHeader("Access-Control-Allow-Origin", "*");
            resp.addHeader("Access-Control-Max-Age", "3628800");
            resp.addHeader("Access-Control-Allow-Methods", "GET, POST, PUT, OPTIONS");
            resp.addHeader("Access-Control-Allow-Headers", "X-Requested-With");
            resp.addHeader("Access-Control-Allow-Headers", "Authorization");




            resp.setChunkedTransfer(true);
return resp;

You can do like this.

Upvotes: 5

Related Questions