繁体   English   中英

已保存的视频未出现在图库中

[英]saved video doesn't appear in gallery

我希望有人可以帮助我解决这个问题。

我有一个可让用户拍摄视频(.mp4)或选择现有视频的应用程序。 如果要拍摄视频,则视频将保存到公共目录中,并且我触发了Android扫描文件以将其添加到媒体库。

问题是 ,拍摄视频效果很好,我可以在我的应用中预览完成的视频。 但是,即使同一文件夹中的其他.mp4出现在列表中,该视频也不会出现在媒体库中,并且其他应用程序-FileManager-都无法访问。

更多信息

  • 在FileManager应用中,未显示的文件带有图标视频图标,而出现的文件带有缩略图。 我可以通过将这些未出现的文件剪切并粘贴到FileManager应用程序中来触发将这些未出现的文件添加到媒体库应用程序中(因此,我相信这不是由于文件已损坏)。
  • 扫描代码适用于从现有相机应用程序拍摄图像的我的代码,但不适用于视频图像...

是否需要其他许可才能工作? 我已经添加/请求/请求了对ext的读写权限。 我的清单和代码中的存储和摄像头。

下面是我拍摄视频并将其扫描到图库中的方法:

private void takeVideo() {
    Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);

    if (takeVideoIntent.resolveActivity(ctx.getPackageManager()) != null) {

        // Create the file where photo should go
        File mediaFile = null;

        try {
            mediaFile = getOutputMediaFile(ctx, MEDIA_TYPE_VIDEO);

        } catch (IOException ex) {
            Log.e("FragCamera", "takeVideo() : Error occurred while creating File." + ex);
        }

        if (mediaFile != null) {
            Uri mediaUri = Uri.fromFile(mediaFile);

            Log.d("FragCamera", "takeVideo() mediaUri: " + mediaUri);

            currMediaUri = mediaUri;
            currPhotoPath = mediaFile.getAbsolutePath();
            Log.d("FragCamera", "takeVideo() currPhotoPath: " + currPhotoPath);

            //make the new file available for other apps
            updateMediaGallery(mediaFile);

            MediaScannerConnection.scanFile(
                    ctx,
                    new String[]{currPhotoPath},
                    new String[]{"video/mp4"},
                    new MediaScannerConnection.OnScanCompletedListener() {
                        @Override
                        public void onScanCompleted(String path, Uri uri) {
                            Log.v("FragCameraScan",
                                    "file " + path + " was scanned seccessfully: " + uri);
                        }
                    });

            takeVideoIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, mediaUri);
            this.startActivityForResult(takeVideoIntent, I_REQUEST_VIDEO_CAPTURE);
        }

    }
}

private void galleryAddPic(String filePath) {
    Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
    File f = new File(filePath);
    Uri contentUri = Uri.fromFile(f);
    mediaScanIntent.setData(contentUri);
    ctx.sendBroadcast(mediaScanIntent);
}

上面代码中每个Log的Logcat值:

 D/FragCamera: takeVideo() mediaUri: file:///storage/emulated/0/DCIM/Camera/VID_20161207_142021.mp4
 D/FragCamera: takeVideo() currPhotoPath: /storage/emulated/0/DCIM/Camera/VID_20161207_142021.mp4
 V/FragCameraScan: file /storage/emulated/0/DCIM/Camera/VID_20161207_142021.mp4 was scanned seccessfully: null

尝试使用此功能

public Uri addVideo(File videoFile) {
    ContentValues values = new ContentValues(3);
    values.put(MediaStore.Video.Media.TITLE, "My video title");
    values.put(MediaStore.Video.Media.MIME_TYPE, "video/mp4");
    values.put(MediaStore.Video.Media.DATA, videoFile.getAbsolutePath());
    return getContentResolver().insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, values);
}

“值”只是有关视频的元数据

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM