Video File Transfer From Android Phone To Server
I'm writing a video processing Android application. The user of the application would take a video, and the application would send the video to the server for some frame by frame p
Solution 1:
Sending video to server from byte[] may cause outOfMemoryError so its better to post video from MultiPart. You can download jar file from this link. http://hc.apache.org/downloads.cgi . Download and add httpmime-4.2.jar to your project.
publicvoiduploadVideo(Context context, String videoPath) {
try {
HttpClienthttpClient=newDefaultHttpClient();
HttpPostpostRequest=newHttpPost(context.getString(R.string.url_service_fbpost));
MultipartEntityreqEntity=newMultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
if(!videoPath.isEmpty()){
FileBodyfilebodyVideo=newFileBody(newFile(videoPath));
reqEntity.addPart("uploaded", filebodyVideo);
}
postRequest.setEntity(reqEntity);
HttpResponseresponse= httpClient.execute(postRequest);
BufferedReaderreader=newBufferedReader(newInputStreamReader(
response.getEntity().getContent(), "UTF-8"));
String sResponse;
StringBuilders=newStringBuilder();
while ((sResponse = reader.readLine()) != null) {
s = s.append(sResponse);
}
Log.e("Response: ", s.toString());
returntrue;
} catch (Exception e) {
Log.e(e.getClass().getName(), e.getMessage());
returnfalse;
}
}
Solution 2:
I found that the compression ratio could be about 16:1. Enough for me to choose to compress it in this situation. The above ratio is if I compressed it to a JPEG.
Post a Comment for "Video File Transfer From Android Phone To Server"