尽管有效的文件路径

时间:2017-10-08 08:45:57

标签: android kotlin

到目前为止浪费了几个小时,所以寻求一些帮助。我之前有这个代码工作,所以现在真的很难过。我正在检查文件是否存在而且确实存在,但仍然没有乐趣。我有

 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)

1 个答案:

答案 0 :(得分:0)

对于其他任何人来说,这是SDK 23的权限。

我必须要求enter image description here才能使用此功能。对这样一个成熟平台上的神秘错误消息印象不深!