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?