0
private void dispatchTakeVideo() throws InterruptedException {

    String path = Environment.getExternalStorageDirectory().getAbsolutePath()
             + "/balloon_launch/" +  System.currentTimeMillis()+ ".3gp";
    recorder = new MediaRecorder();
    recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
    recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
    recorder.setOutputFile(path);
    recorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT);
    recorder.setMaxDuration(3600); 
    recorder.setVideoSize(320, 240);
    recorder.setVideoFrameRate(15); 
    Thread.sleep(10000); 
    try {
            recorder.prepare();
            Thread.sleep(5000);
        } catch (IOException e) {
            Log.e("Recording","prepare() failed");
        }
    Thread.sleep(5000);
    recorder.start();
    Thread.sleep(5000);
}

我正在尝试以编程方式在我的应用程序中启动视频录制,但是,我很难让媒体记录器工作。我得到一个非法状态异常,调试后,我知道 prepare() 方法给我造成了问题......有几个人建议其他类似使用 Thread.sleep() 的问题,所以我已经包括了几个地方,但这也不起作用...我在下面的评论中包含了视频的方法、logcat 和权限..我想知道这是否与我在 xml 中没有做任何事情的事实有关活动及其原因是我不想在屏幕上显示我录制的视频,我只想让它在某个时间录制......感谢您的帮助。

这是原木猫

11-22 11:14:38.327: E/Trace(795): error opening trace file: No such file or directory (2)
11-22 11:14:39.007: D/dalvikvm(795): GC_FOR_ALLOC freed 51K, 3% free 8055K/8259K, paused      35ms, total 37ms
11-22 11:14:39.027: I/dalvikvm-heap(795): Grow heap (frag case) to 9.743MB for 1918240-  byte allocation
11-22 11:14:39.097: D/dalvikvm(795): GC_CONCURRENT freed 1K, 3% free 9927K/10183K, paused  24ms+5ms, total 71ms
11-22 11:14:39.387: D/gralloc_goldfish(795): Emulator without GPU emulation detected.
11-22 11:14:52.650: E/Recording(795): prepare() failed
11-22 11:14:57.653: E/MediaRecorder(795): start called in an invalid state: 4
11-22 11:14:57.653: D/AndroidRuntime(795): Shutting down VM
11-22 11:14:57.656: W/dalvikvm(795): threadid=1: thread exiting with uncaught exception      (group=0x40a13300)
11-22 11:14:57.666: E/AndroidRuntime(795): FATAL EXCEPTION: main
11-22 11:14:57.666: E/AndroidRuntime(795): java.lang.IllegalStateException
11-22 11:14:57.666: E/AndroidRuntime(795):  at android.media.MediaRecorder.start(Native  Method)
11-22 11:14:57.666: E/AndroidRuntime(795):  at  com.finding.videoing.sharing.MainActivity.dispatchTakeVideoIntent(MainActivity.java:148)
11-22 11:14:57.666: E/AndroidRuntime(795):  at   com.finding.videoing.sharing.MainActivity.access$0(MainActivity.java:129)
11-22 11:14:57.666: E/AndroidRuntime(795):  at    com.finding.videoing.sharing.MainActivity$1.onClick(MainActivity.java:61)
11-22 11:14:57.666: E/AndroidRuntime(795):  at    android.view.View.performClick(View.java:4084)
11-22 11:14:57.666: E/AndroidRuntime(795):  at     android.view.View$PerformClick.run(View.java:16966)
11-22 11:14:57.666: E/AndroidRuntime(795):  at   android.os.Handler.handleCallback(Handler.java:615)
11-22 11:14:57.666: E/AndroidRuntime(795):  at  android.os.Handler.dispatchMessage(Handler.java:92)
11-22 11:14:57.666: E/AndroidRuntime(795):  at android.os.Looper.loop(Looper.java:137)
11-22 11:14:57.666: E/AndroidRuntime(795):  at   android.app.ActivityThread.main(ActivityThread.java:4745)
11-22 11:14:57.666: E/AndroidRuntime(795):  at       java.lang.reflect.Method.invokeNative(Native Method)
11-22 11:14:57.666: E/AndroidRuntime(795):  at   java.lang.reflect.Method.invoke(Method.java:511)
11-22 11:14:57.666: E/AndroidRuntime(795):  at   com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
11-22 11:14:57.666: E/AndroidRuntime(795):  at   com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-22 11:14:57.666: E/AndroidRuntime(795):  at dalvik.system.NativeStart.main(Native  Method)
4

0 回答 0