2016-06-28 4 views
0

私はMediaRecorderオブジェクトにsetVideoSourceを呼び出すと、それは、IllegalStateExceptionがをスローします。setVideoSource(た:IllegalStateExceptionが)

(Android SDk 2.1) Getting error when I use setAudioSource and setVideoSource

Why following code shows setVideoSource failed exception setvideosourceに失敗した例外

MediaPlayer.prepare() throws IllegalStateException on Android L

しかし、解決策は助けまたは不適切なされていないのいずれかの提案:私はこれらをチェックしました。私はsetOutputFormatがsetVideoSource前に呼び出されていないことを確信

private void initRecorder() { 
    Log.i(TAG, "InitRecorder"); 
    if(mRecorder == null) { 
     mRecorder = new MediaRecorder(); 
     mRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT); 
     mRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT); 
     mRecorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT); 
     mRecorder.setVideoSize(640, 480); 
     mRecorder.setVideoFrameRate(30); 
     mRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT); 
     mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT); 
     CamcorderProfile cpHigh = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH); 
     mRecorder.setProfile(cpHigh); 
     mRecorder.setOutputFile("/sdcard/video.mp4"); 
     mRecorder.setMaxDuration(50000); // 50 seconds 
     mRecorder.setMaxFileSize(5000000); // Approximately 5 megabytes 
    } 
} 

、正しい権限が要求され、付与されており、ちょうど1ビデオレコーダオブジェクトが存在している:

コードは次のようになります。

私はMarshmallowをインストールしたMoto GでAndroid SDK 23を使用しています。

誰にもアイデアはありますか?例外からより多くの情報を得ることは有益でしょうが、Android Studioは何とかそれを手放すことはできません。私は関連する質問は、それがスローされた時点でどのように例外を調べることができるだろうと思いますか? IllegalStateExceptionであるという事実より多くの情報を含む可能性はありますか?

例外は今やRunTimeExceptionに変更されました。これは混乱します。私はそれがIllegalStateExceptionをスローする必要がありますが、それはかなり今RunTimeExceptionに固執しているので、私はそれに行った変更をバックアウトしました。

06-28 13:10:14.989 30933-30933/com.dogtail W/ActivityThread: Application com.dogtail is waiting for the debugger on port 8100... 
06-28 13:10:14.990 30933-30933/com.dogtail I/System.out: Sending WAIT chunk 
06-28 13:10:15.142 30933-30939/com.dogtail I/art: Debugger is active 
06-28 13:10:15.190 30933-30933/com.dogtail I/System.out: Debugger has connected 
06-28 13:10:15.191 30933-30933/com.dogtail I/System.out: waiting for debugger to settle... 
06-28 13:10:15.391 30933-30933/com.dogtail I/System.out: waiting for debugger to settle... 
06-28 13:10:15.591 30933-30933/com.dogtail I/System.out: waiting for debugger to settle... 
06-28 13:10:15.791 30933-30933/com.dogtail I/System.out: waiting for debugger to settle... 
06-28 13:10:15.992 30933-30933/com.dogtail I/System.out: waiting for debugger to settle... 
06-28 13:10:16.192 30933-30933/com.dogtail I/System.out: waiting for debugger to settle... 
06-28 13:10:16.392 30933-30933/com.dogtail I/System.out: waiting for debugger to settle... 
06-28 13:10:16.592 30933-30933/com.dogtail I/System.out: debugger has settled (1312) 
06-28 13:10:16.636 30933-30933/com.dogtail W/System: ClassLoader referenced unknown path: /data/app/com.dogtail-1/lib/arm 
06-28 13:10:17.599 30933-30933/com.dogtail W/System: ClassLoader referenced unknown path: /data/app/com.dogtail-1/lib/arm 
06-28 13:10:17.681 30933-30933/com.dogtail I/APPLICATION: onCreate 
06-28 13:10:17.934 30933-31061/com.dogtail I/Adreno-EGL: <qeglDrvAPI_eglInitialize:379>: QUALCOMM Build: 10/09/15, 6cbbf7d, I3193f6e94a 
06-28 13:10:17.936 30933-31061/com.dogtail I/OpenGLRenderer: Initialized EGL, version 1.4 
06-28 13:10:20.588 30933-30933/com.dogtail I/VideoRecorder: OnCreate 
06-28 13:10:20.588 30933-30933/com.dogtail I/VideoRecorder: InitRecorder 
06-28 13:10:20.598 30933-30933/com.dogtail E/AndroidRuntime: FATAL EXCEPTION: main 
                  Process: com.dogtail, PID: 30933 
                  java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dogtail/com.dogtail.VideoRecorder}: java.lang.RuntimeException: setVideoSource failed. 
                   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2426) 
                   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490) 
                   at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354) 
                   at android.os.Handler.dispatchMessage(Handler.java:102) 
                   at android.os.Looper.loop(Looper.java:148) 
                   at android.app.ActivityThread.main(ActivityThread.java:5443) 
                   at java.lang.reflect.Method.invoke(Native Method) 
                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728) 
                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 
                   Caused by: java.lang.RuntimeException: setVideoSource failed. 
                   at android.media.MediaRecorder.setVideoSource(Native Method) 
                   at com.dogtail.VideoRecorder.initRecorder(VideoRecorder.java:45) 
                   at com.dogtail.VideoRecorder.onCreate(VideoRecorder.java:30) 
                   at android.app.Activity.performCreate(Activity.java:6245) 
                   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1130) 
                   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379) 
                   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490)  
                   at android.app.ActivityThread.-wrap11(ActivityThread.java)  
                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354)  
                   at android.os.Handler.dispatchMessage(Handler.java:102)  
                   at android.os.Looper.loop(Looper.java:148)  
                   at android.app.ActivityThread.main(ActivityThread.java:5443)  
                   at java.lang.reflect.Method.invoke(Native Method)  
                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)  
                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)  
+0

エラーログを追加してください。 – USKMobility

答えて

0

あなたがsetOutputFormatとsetProfileの両方を使用している:うーん...ここ

はエラーログです。

削除し、次の行

mRecorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);.

とエラー離れ

を行くあなたはまた、ライン

mRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT)を削除する必要があります。 mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);

mRecorder.setProfile(cpHigh);これらのプロパティはデフォルトで既に追加されています。

+0

setOutputFormatの前にあるsetVideoSource行に例外がスローされているので、それはそれだとは思わない... –

+0

setOutputFormatプロパティが2回追加され、setProfileもこのプロパティを追加しました。アンドロイドメディアフレームワークはあまりスマートではありません – USKMobility

+0

しかし、setOutputFormatがまったく呼び出される前に例外がスローされていますか? –

関連する問題