-1
這個目前浪費了幾個小時,所以尋找一些幫助。我之前已經有了這個代碼,所以現在真的難倒了。我正在檢查文件是否存在,它確實存在,但仍然沒有快樂。我有ThumbnailUtils.createVideoThumbnail儘管有效的文件路徑崩潰
var vidIntent = Intent(MediaStore.ACTION_VIDEO_CAPTURE)
var g1 = UUID.randomUUID()
var vidFileName = "$g1.mp4"
_videoFileList.add(vidFileName)
var videoFileDir = Environment.getExternalStoragePublicDirectory(android.os.Environment.DIRECTORY_MOVIES)
var vidFile = File(videoFileDir, vidFileName)
_capturedVideoPath = vidFile.absolutePath
vidIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(vidFile))
vidIntent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, 10)
startActivityForResult(vidIntent, 0)
然後處理結果:
if (!_capturedVideoPath.isBlank()){
println("video captured at $_capturedVideoPath")
if (!File(_capturedVideoPath).exists()){
throw Exception("File at $_capturedVideoPath does not exist")
}
var thumbBmp : Bitmap = ThumbnailUtils.createVideoThumbnail(_capturedVideoPath, MediaStore.Video.Thumbnails.MINI_KIND)
總是導致下列崩潰(測試在真實設備上):
E/ExceptionHandler: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=0, result=-1, data=Intent { dat=file:///storage/emulated/0/Movies/084ea076-995f-4818-9536-4a9184167ccf.mp4 flg=0x1 (has extras) }} to activity {com.reels.videocapture/com.example.live.videocapture.ShootVideoActivity}: java.lang.IllegalStateException: ThumbnailUtils.createVid…deo.Thumbnails.MINI_KIND) must not be null
at android.app.ActivityThread.deliverResults(ActivityThread.java:3730)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3773)
at android.app.ActivityThread.access$1400(ActivityThread.java:165)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1418)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:150)
at android.app.ActivityThread.main(ActivityThread.java:5546)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:682)
Caused by: java.lang.IllegalStateException: ThumbnailUtils.createVid…deo.Thumbnails.MINI_KIND) must not be null
at com.example.live.videocapture.ShootVideoActivity.onActivityResult(ShootVideoActivity.kt:97)
at android.app.Activity.dispatchActivityResult(Activity.java:6597)
at android.app.ActivityThread.deliverResults(ActivityThread.java:3726)
這是什麼代碼的輸出是它的條件bloack 如果內部發出(!文件(_capturedVideoPath).exists()){ 拋出異常( 「文件在$ _capturedVideoPath不存在」) } –
logcat的可能看起來很奇怪,因爲這是我的另一個問題,當我的應用程序崩潰時,Logcat中沒有任何內容,所以我在SO上發現了一些覆蓋'DefaultUncaughtExceptionHandler'的代碼。 @AbdulWaheed它不會拋出異常,因此文件路徑很好。 – PhilG