我正在开发一种最简单的视频录制玻璃器皿。该应用程序在我的Android手机(DROID X)和虚拟设备中运行良好,但在Google Glass LogCat中说明如下。我现在遇到的两个问题是:
没有输出文件或大小为ZERO的输出文件。
06-17 12:54:24.805:E / CameraService-GoogleCamera(1925):ERROR - Burst 0 info预期,未找到
06-17 12:54:24.805:E / BufferQueue(1925):[unnamed-1925-0] setBufferCount:client拥有一些缓冲区
06-17 12:54:24.977:A / OMXCodec(1925):frameworks / av / media / libstagefright / OMXCodec.cpp:4219 CHECK_EQ( 错误,(status_t)OK)失败:-2147483648 vs. 0
06-17 12:54:24.977:A / libc(1925):致命信号6(SIGABRT)位于0x00000785(代码= -6),线程1961(Binder_1)
06-17 12:54:25.469:E / AudioService(514):媒体服务器已经死亡。
06-17 12:54:25.969:E / AudioService(514):媒体服务器已启动。
代码如下
package edu.ds.cameracontrolandroid;
import java.io.File;
import java.io.IOException;
import edu.ds.cameracontrolandroid.R;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.hardware.Camera;
import android.hardware.Camera.Size;
import android.media.CamcorderProfile;
import android.media.MediaRecorder;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;
public class MainActivity extends ActionBarActivity implements SurfaceHolder.Callback {
public static final String LOGTAG = "DS";
private MediaRecorder recorder;
private SurfaceHolder holder;
boolean recording = false;
private String filename = "";
private boolean recordClosed = false;
SurfaceView cameraView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
String state = Environment.getExternalStorageState();
if (!Environment.MEDIA_MOUNTED.equals(state)) {
Log.e(LOGTAG,"external storage not writable");
}
cameraView = (SurfaceView) findViewById(R.id.CameraView);
holder = cameraView.getHolder();
holder.addCallback(this);
Handler handler=new Handler();
Runnable r=new Runnable(){
public void run() {
Log.e(LOGTAG,"runnable");
finish();
}
};
handler.postDelayed(r, 15000);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container,
false);
return rootView;
}
}
public void surfaceCreated(SurfaceHolder holder) {
}
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
Log.e(LOGTAG, "surfaceChanged");
recorder = new MediaRecorder();
recorder.setPreviewDisplay(holder.getSurface());
recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT);
recorder.setMaxDuration(1000 * 15);
//recorder.setOnInfoListener(self);
//Camera camera = Camera.open();
//Size size = camera.getParameters().getSupportedPreviewSizes().get(0);
//recorder.setVideoSize(size.width, size.height);
recorder.setVideoFrameRate(15);
try {
File newFile = File.createTempFile("videocapture", ".mp4", Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM));
//File mediaStorageDir = new File(Environment.getExternalStorageDirectory()+File.separator+"DCIM/Camera");
//recorder.setOutputFile(newFile.getAbsolutePath());
filename = newFile.getAbsolutePath();
Log.e(LOGTAG, "file -- " + filename);
recorder.setOutputFile(filename);
}
catch (IOException e) {
Log.e(LOGTAG, "Couldn't create file -- " + filename);
e.printStackTrace();
finish();
return;
}
try {
recorder.prepare();
recorder.start();
}
catch(Exception e){
Log.e(LOGTAG, "prepare --" + e.toString()); **//There is no error message printed out here!!!**
finish();
}
}
public void surfaceDestroyed(SurfaceHolder holder) {
Log.e(LOGTAG, "surfaceDestroyed");
finish();
}
@Override
public void finish(){
if(recordClosed) return;
try{
recorder.stop();
recorder.release();
Log.e(LOGTAG,"stopping");
recordClosed = true;
}
catch(Exception e){
Log.e(LOGTAG, e.toString());
e.printStackTrace();
}
}
}