我编写了在 android 上录制视频的代码,我将它上传到 Blobstore,但没有运气让它从 googleappengine 上的播放器播放或在网络应用程序上流式传输,但是,我可以在下载视频时阅读它。任何想法 ??我想到了我正在使用的编码或视频格式(.mp4)甚至更多,我将字节发送到 blobstore 的方式。谢谢你。
这是录制代码:
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();
这是上传代码:
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();
“url”参数是从blobstore生成的url,用于上传媒体文件,我猜blobstore用户对它很熟悉。