I wrote the code to record a video on android, I upload it to the Blobstore, but no luck in getting it play either from the player on googleappengine or stream it on a web application however, I can read the video when I download it. Any idea ?? I thought of the encodings I am using or the video format(.mp4) or even more, the way i send the bytes to the blobstore. thank you.
here is the recording code:
mCamera = Camera.open();
path= Environment.getExternalStorageDirectory().getAbsolutePath().toString();
Date date=new Date();
filename="/rec"+date.toString().replace(" ", "_").replace(":", "_")+".mp4";
//create empty file it must use
File file=new File(path,filename);
mrec = new MediaRecorder();
mCamera.lock();
mCamera.unlock();
mrec.setCamera(mCamera);
mrec.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
mrec.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
mrec.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
mrec.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT);
mrec.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mrec.setVideoFrameRate(20);
mrec.setPreviewDisplay(surfaceHolder.getSurface());
mrec.setOutputFile(path+filename);
mrec.prepare();
mrec.start();
and here is the uploading code:
HttpClient httpclient = new DefaultHttpClient();
httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
//HttpPost httppost = new HttpPost(url);
HttpPost httppost = new HttpPost(url);
File file = new File("/sdcard/"+videoName);
MultipartEntity mpEntity = new MultipartEntity();
ContentBody cbFile = new FileBody(file, "video/mp4");
mpEntity.addPart("videoFile", cbFile);
httppost.setEntity(mpEntity);
System.out.println("executing request " + httppost.getRequestLine());
HttpResponse response = httpclient.execute(httppost);
HttpEntity resEntity = response.getEntity();
the "url" parameter is the generated url from the blobstore in order to upload the media file, i guess blobstore users are familiar with it.
Try using OutputFormat.MPEG_4
, VideoEncoder.H264
and AudioEncoder.AAC
.