android - 录制的视频无法立即从文件位置读取?

标签 android mediastore video-recording android-external-storage file-read

我正在使用我的 android 应用程序录制视频。当我在录制后尝试从路径中读取视频时,我没有得到完整的录制文件。 但过了一段时间我可以阅读完整的文件。我不知道是什么问题? 请帮忙。 这是我的代码

尝试{ videoFile = getOutputMediaFile(MEDIA_TYPE_VIDEO); videothumb = new File(getOutputMediaThumbFile(MEDIA_TYPE_VIDEO), videoFile.getName()); db.insertFileInfo(videoFile.getName(), 0, videoFile.length(), 0, "video/mp4"); 如果(videoFile == null){ Log.d("", "创建媒体文件出错,检查存储权限:"); safeToTakePicture = true; 返回空值;

            videothumb.createNewFile();
            videoFile.createNewFile();
            Thread.sleep(10000);
            upVFile = new File(videoFile.getAbsolutePath());
            FileOutputStream fos = new FileOutputStream(videoFile);
            FileOutputStream ftos = new FileOutputStream(videothumb);
            thumb = Bitmap.createScaledBitmap(bmv, 200, 200, false);
            thumb.compress(Bitmap.CompressFormat.JPEG, 90, ftos);
            ftos.flush();
            ftos.close();
            bmv.compress(Bitmap.CompressFormat.JPEG, 100, fos);
            fos.flush();
            fos.close();
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            bmv.compress(Bitmap.CompressFormat.JPEG, 100, baos);
            byte[] b = baos.toByteArray();
            baos.close();
            String encodedImage = new String(Base64.encodeBase64(b));
            editor.putString("image_data", encodedImage);
            editor.commit();
            editor.putString(IMAGE_NAME, videoFile.getName());
            editor.commit();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
        }

最佳答案

写一个刷新图库的方法

private void refreshGallery(File file){

Intent mediaScanIntent=new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);

mediaScanIntent.setData(Uri.fromFile(file));

sendBroadcast(mediaScanIntent);

}

关于android - 录制的视频无法立即从文件位置读取?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36265120/

相关文章:

android - Glide Picasso 不会加载本地存储视频的缩略图路径

java - Android - Android4.0中的MediaPlayer异常

javascript - 我可以通过单击该 html 文件中的按钮来录制我的屏幕/网页吗?

安卓 map 十字标记

Android RecyclerView 添加分页

android - 在Android中使用mp.stop()时出现错误

java - 如何实现在深色背景上运行的进度条?

Android Camera Intent - 内存不足错误和旋转错误

Java Android getContentResolver().query 特定相机文件夹以获取 Android API 级别 <= 28 设备中的光标

android - 在我重新启动平板电脑 Asus Transformer 之前,录制的视频在我的其他 Activity 中不可见