java.lang.RuntimeException: stop failed.
阿新 • • 發佈:2018-11-04
FATAL EXCEPTION: main
Process: com.gdvictor.dbconductorcenter, PID: 15341
java.lang.RuntimeException: stop failed.
at android.media.MediaRecorder.stop(Native Method)
at com.gdvictor.dbconductorcenter.activity_model.Manager.stopRecord(Manager.java:123)
at com.gdvictor.dbconductorcenter.activity_model.Manager.startRecord(Manager.java:108)
at com.gdvictor.dbconductorcenter.activity.VideoChatViewActivity_2.onClick(VideoChatViewActivity_2.java:356)
at android.view.View.performClick(View.java:5267)
at android.view.View$PerformClick.run(View.java:21540)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5791)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901)
。
Process: com.gdvictor.dbconductorcenter, PID: 15341
java.lang.RuntimeException: stop failed.
at android.media.MediaRecorder.stop(Native Method)
at com.gdvictor.dbconductorcenter.activity_model.Manager.stopRecord(Manager.java:123)
at com.gdvictor.dbconductorcenter.activity_model.Manager.startRecord(Manager.java:108)
at com.gdvictor.dbconductorcenter.activity.VideoChatViewActivity_2.onClick(VideoChatViewActivity_2.java:356)
at android.view.View.performClick(View.java:5267)
at android.view.View$PerformClick.run(View.java:21540)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5791)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762)
報錯說明:
魅族手機 Android5.0 執行正常
小米 Android 6.0 執行報錯:
解決方案:
1.新增錄音許可權 後執行
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
2.若果繼續報錯的話,請檢視軟體是否授權。請進入手機設定-應用,找到自己的應用,給應用授權
除錯過程中除了第一次安裝會提示授權外,再次安裝不提示,如果使用者沒有授予應用相應的錄音和sdcard寫許可權,程式依然會報錯。
3.若果繼續報錯,檢視是否添加了Android 6.0 動態許可權申請
if (Build.VERSION.SDK_INT >= 23) { int checkCallPhonePermission2 = ContextCompat.checkSelfPermission(mActivity, Manifest.permission.WRITE_EXTERNAL_STORAGE); int checkCallPhonePermission3 = ContextCompat.checkSelfPermission4.若果繼續報錯,請更改錄音來源(mActivity, Manifest.permission.RECORD_AUDIO); if (checkCallPhonePermission2 != PackageManager.PERMISSION_GRANTED && checkCallPhonePermission3 != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(mActivity, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.RECORD_AUDIO}, 123); return; } }
將這句
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);改換成
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.VOICE_COMMUNICATION);