我想从我的活动中捕捉视频
这是我的源代码
mTempVideoPath = Environment.getExternalStorageDirectory().getName() + File.separatorChar + "Android/data/" + this.getPackageName() + "/files/" + System.currentTimeMillis() + ".mp4";
File videoFile = new File(mTempVideoPath);
try {
if(videoFile.exists() == false) {
videoFile.getParentFile().mkdirs();
videoFile.createNewFile();
}
} catch (IOException e) {
Log.e(getCallingPackage(), "Could not create file.", e);
}
mCurrentVideoURI = Uri.fromFile(videoFile);
Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE );
intent.putExtra( MediaStore.EXTRA_OUTPUT, mCurrentVideoURI);
// preventing it from listing items that aren't on the SD card
intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
startActivityForResult(intent, CAPTURE_VIDEO);
但我得到这个错误:
09-17 18:25:28.945: E/AndroidRuntime(30253): FATAL EXCEPTION: main
09-17 18:25:28.945: E/AndroidRuntime(30253): java.lang.NullPointerException
09-17 18:25:28.945: E/AndroidRuntime(30253): at java.io.File.fixSlashes(File.java:185)
09-17 18:25:28.945: E/AndroidRuntime(30253): at java.io.File.<init>(File.java:134)
09-17 18:25:28.945: E/AndroidRuntime(30253): at com.sec.android.app.camera.CamcorderEngine.renameTempFile(CamcorderEngine.java:1467)
09-17 18:25:28.945: E/AndroidRuntime(30253): at com.sec.android.app.camera.CamcorderEngine.doStopVideoRecordingSync(CamcorderEngine.java:965)
09-17 18:25:28.945: E/AndroidRuntime(30253): at com.sec.android.app.camera.CeStateRecording.handleRequest(CeStateRecording.java:69)
09-17 18:25:28.945: E/AndroidRuntime(30253): at com.sec.android.app.camera.CeRequestQueue.startFirstRequest(CeRequestQueue.java:123)
09-17 18:25:28.945: E/AndroidRuntime(30253): at com.sec.android.app.camera.CeRequestQueue.access$200(CeRequestQueue.java:32)
09-17 18:25:28.945: E/AndroidRuntime(30253): at com.sec.android.app.camera.CeRequestQueue$MainHandler.handleMessage(CeRequestQueue.java:60)
09-17 18:25:28.945: E/AndroidRuntime(30253): at android.os.Handler.dispatchMessage(Handler.java:99)
09-17 18:25:28.945: E/AndroidRuntime(30253): at android.os.Looper.loop(Looper.java:137)
09-17 18:25:28.945: E/AndroidRuntime(30253): at android.app.ActivityThread.main(ActivityThread.java:4507)
09-17 18:25:28.945: E/AndroidRuntime(30253): at java.lang.reflect.Method.invokeNative(Native Method)
09-17 18:25:28.945: E/AndroidRuntime(30253): at java.lang.reflect.Method.invoke(Method.java:511)
09-17 18:25:28.945: E/AndroidRuntime(30253): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
09-17 18:25:28.945: E/AndroidRuntime(30253): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
09-17 18:25:28.945: E/AndroidRuntime(30253): at dalvik.system.NativeStart.main(Native Method)
我在 Galaxy S2、ICS 上运行!
请帮帮我!
谢谢