0

I want to cast local data (Image/Video) that are selected from gallery and served on the local web server using NanoHTTPD server. code to serve the image is :

public class MyServer extends NanoHTTPD {
    FileInputStream fileInputStream;
    private final static int PORT = 8888;


    public MyServer() throws IOException {
        super(PORT);
        start();
        System.out.println("\nRunning! Point your browers to http://localhost:8888/ \n");
    }

    public Response serve(String uri, Method method, Map<String, String> header, Map<String, String> parameters, Map<String, String> files) {
        String mediasend = " ";
        FileInputStream fis = null;
        String file;
        String answer = "";

        try {
            fis = new FileInputStream( selectedImagePath );
            mediasend= selectedImagePath.substring(selectedImagePath.lastIndexOf(".")+1);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

        return new NanoHTTPD.Response(com.madhu.imageonserver.Server.NanoHTTPD.Response.Status.OK, mediasend, fis);
    }
}

where selectedImagePath is : "/storage/sdcard0/whatsApp/WhatsApp Images/IMG-20160409-WA000.jpg". mediaInfo to cast the Image is .

 mediaMetadata.putString(com.google.android.gms.cast.MediaMetadata.KEY_TITLE, getString(R.string.image_title));

    MediaInfo mediaInfo = new MediaInfo.Builder(ipdevice)
            .setContentType(getString(R.string.content_type_jpg))
            .setStreamType(MediaInfo.STREAM_TYPE_BUFFERED)
            .setMetadata(mediaMetadata)
            .build();

where mediaInfo: MediaInfo@830029452976 ipdevice: "http://192.168.x.x:8888".

Server is started in onCreate:

    WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
    WifiInfo wifiInfo = wifiManager.getConnectionInfo();
    int ipAddress = wifiInfo.getIpAddress();
    ipdevice = String.format("http://%d.%d.%d.%d:8888", (ipAddress & 0xff), (ipAddress >> 8 & 0xff), (ipAddress >> 16 & 0xff), (ipAddress >> 24 & 0xff));

    try {
        server.start();
    } catch (IOException ioe) {
        Log.d("Httpd", "The server could not start.");
    }

but there is nothing happened when I try to cast the image. The aim is to cast the local data like image and video.

Can anyone suggest me better solution?

Kara
  • 6,115
  • 16
  • 50
  • 57
jyoti
  • 1
  • 1
  • On, say, your laptop, can you open the same URL that you are sending to your chromecast to see if you can see your image in the browser running on your laptop? And what does your receiver console log shows when you send it an image? – Ali Naddaf Apr 09 '16 at 20:16
  • yes, i can open the same URL that are sending to chromecast but i could not see the image in the browser. – jyoti Apr 10 '16 at 09:11
  • I can open the same URL and image is displayed on the browser but still there is nothing happened when i try to cast the image. – jyoti Apr 14 '16 at 07:07
  • Enable debugging on receiver and check the console log – Ali Naddaf Apr 14 '16 at 07:46

0 Answers0