I'm working on android app and back-end server Rest API part.
I'm at the point where i need to return some video files from the server back to my android device. How can i do that?
I looked up jersey documantation https://jersey.java.net/documentation/1.19/jax-rs.html#d4e142
and http://www.vogella.com/tutorials/REST/article.html#restjersey_annotations
but din't have any luck figuring this out..
For images i've been using the
#Produces(image/jpg)
Is there a similar way i can do to share mpeg4 or any other video files?
What would be the best approach there?
As android client can stream the video content, try something like this
#GET
#Path("video")
#Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response video() {
File file = new File("C:/Data/video.mp4");
return Response.ok(file, MediaType.APPLICATION_OCTET_STREAM)
.build();
}
Related
I want to programm a messenger, which runs on a Server and can send an zip file at any size. So you would send the zip file to the server and when any other person is online, the server sends the zip File to the other person. I have no idea what servertype I could use and when I was reserching I found nothing. Because I want to run the sever on my Raspberry Pi, it would be also helpfull, if I could slow the datastream down. It would be very helpful, if one of you could recommend servertypes, classes or methods, so that I can do more research.
Thank you in advance
You can create a maven-project on EclipseIDE and use Jersey for API-layer (tutorial: https://www.journaldev.com/498/jersey-java-tutorial).
Your class:
#Path("/zip")
public class ZIPRest{
#POST
#Path("/upload")
#Consumes("application/json")
#Produces("application/json")
public Response uploadZIP(InputStream file){
// TODO: convert InputStream in BLOB and save it on database
}
}
I'm trying to serve an m3u8 playlist through Spring Boot. I have a running ffmpeg process that is transcoding a multicast in real-time and sending the files to /src/resources/public/output.m3u8. I see the playlist updating and the new .ts files being generated correctly however when trying to watch the stream in a video player, it only plays a certain amount of video. Is there a way to properly serve up a running playlist in Java instead of serving it statically?
EDIT: When starting a basic http server with python python3 -m http.server, I'm able to view the stream perfectly fine. Is there a Spring Boot way to accomplish the same task?
With Spring 4.1 your approach will work there is no issue in it. Here below is another approach in case if you want to look
#RequestMapping(value = "/VMS-49001/playlist/{listName:.+}")
public ResponseEntity<byte[]> testphoto() throws IOException {
InputStream in = servletContext.getResourceAsStream("/images/no_image.jpg");
final HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.parseMediaType("application/vnd.apple.mpegurl"));
headers.setContentDispositionFormData(fileName, fileName);
return new ResponseEntity<byte[]>(IOUtils.toByteArray(in), headers, HttpStatus.CREATED);
}
Hey I created a neural network using python, this network can recognize handwritten digits. I want to use this in my android app. The android app will take a picture of a hand written digit, and send it to the neural network, the neural network will figure out the digit and send it back to the app. How would I do this? I looked at Google Cloud Platform, but I am confused. I want to know how I will send the picture from the app to my python neural network, and send the output back.
Make yourself familiar with the concepts of REST (RestEasy, Jersey,...), create a REST server with an endpoint that can receive a JSON string which contains your base64 picture. The app converts the picture with base64 and sends it to the REST server. Unencode it in your REST server, delegate it to the python script, convert the result back to JSON and send it back to the app. The app itself receives the JSON and gets the data from it.
This is how I would do it with WildFly server and RestEasy:
//app side
PictureInputBo pictureInputBo = new PictureInputBo([your binary]); //encodes it to base64
//This is working Java code and can be used.
//It will automatically convert to JSON and sent to the "convert" endpoint of the server
ResteasyClient client = new ResteasyClientBuilder().build();
ResteasyWebTarget target = client.target("http://yourserver:8080/your-webservice/rest/convert/");
Response response = target.request().accept(MediaType.APPLICATION_JSON).post(Entity.entity(pictureInputBo, "application/json;charset=UTF-8;version=1"));
//Server side..."Converter Endpoint", this is also working Java code.
//it will automatically converted back to the Java object "PictureInputBo" by RestEasy
#POST
#Path("/convert")
#Consumes(MediaType.APPLICATION_JSON)
public Response convertPicture(#NotNull(message = "Must not be null") #Valid PictureInputBo inputBo)
{
//Here you pass your business object to the converter service which processes the data
//(pass it to python or whatever)
PictureOutputBo result = converterService.convert(inputBo);
//Resteasy converts it back to JSON and responds it to the app.
return Response.ok().entity(result).build();
}
//Back in your app.
check if response.getStatus() == 200) //HTTP Status OK
PictureOutputBo pictureOutputBo = response.readEntity(PictureOutputBo.class);
I need play video from samba to android device streaming. I've been look for this question and someone say that :
Using JCIFS to scan for and "see" the share: http://jcifs.samba.org/
Implementing a simple HTTP server (NanoHttpd) to stream the content
via http: https://github.com/NanoHttpd/nanohttpd
Passing the http://localhost/myvideo link to the VideoView
I'm already use JCIFS to get SmbFile in my project and I also get inputstream( smbfile.getInputStream() ).
Now I import NanoHttpd and I create simple HTTP server that http address ishttp://localhost:8080
private class MyHTTPD extends NanoHTTPD {
public MyHTTPD() throws IOException {
super(8080);
}
#Override
public Response serve(String uri, String method, Properties header, Properties parms, Properties files) {
InputStream is = new SmbFile(filePath,auth).getInputStream();
//return index as response
return new NanoHTTPD.Response(HTTP_OK, "video/mp4", is);
}
}
server = new MyHTTPD();
server.start();
But my http address is different from http://localhost/myvideo, I don't know how to get right http address and put it in to VideoView.
I don't know how to get path like http://localhost/myvideo .
Thanks for help....
The other question : Can I use VideoView playing video from InputStream ?
We are developing an Android Application to download files from Google Doc.We were able to list the files using Google Docs List APIs. Also we were able to download spreadsheet files from google docs. But when we tried to download pdf file from google docs it always returns with 401 error. This is the code snipped we are using to download the file.
CommonsHttpOAuthConsumer consumer = new CommonsHttpOAuthConsumer(C.OAuth.CONSUMER_KEY, C.OAuth.CONSUMER_SECRET);
consumer.setMessageSigner(new HmacSha1MessageSigner());
consumer.setTokenWithSecret(token, secret);
.........
String url1 = consumer.sign(obj.url+"&exportFormat=txt"); // Create complete url
get.setURI(URI.create(url1));
response = client.execute(get);
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK)
{
Log.v("GDATA MAIN", "not error");
}
else
{
Log.v("GDATA MAIN", "error"+response.getStatusLine().getStatusCode());
}
This is the URL that i generate to download the file.
https://doc-04-0s-docs.googleusercontent.com/docs/securesc/5pv2dhsk6q500b1vl99u2gr2gvpqfifr/d8oihkmccnh39ie9io5bhqaf3jof7t16/1324030500000/01234800628230479895/01234800628230479895/0B4royw-5u0TDNGU3ZjZiZTAtN2ZhNi00YWE3LWEwZGEtMTMwNWJhMGE1YWRk?h=16653014193614665626&e=download&gd=true&exportFormat=txt&oauth_signature=3lfP0reuJhMWstxMKMAlJh%2BZ7Ug%3D&oauth_token=1%2FQnEPtLXrhT8q6yk8oLoI2ZPyZzQptbB4mQrBJf-HJfM&oauth_consumer_key=418002400742-nrh3mt73pfvl6flshi8f7uvki49ofqj8.apps.googleusercontent.com&oauth_version=1.0&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1324031523&oauth_nonce=351034367494689817
Any guess, why we are not able to download PDF, but spreadsheet formats are working ?
I think that you are not requesting the correct scopes when authorizing the token. The scopes for which you should request the token are:
https://docs.google.com/feeds/
https://spreadsheets.google.com/feeds/
https://docs.googleusercontent.com/
You just made me realize that a bug was introduced into the Authorization section of our documentation, removing the docs.googleusercontent.com scope. I will add that back.