Record, save and play a video in Android

前端 未结 3 817
南方客
南方客 2021-02-06 09:36

I am trying to make an app that records a video using the camera app, and then saves that video on SD card so I can play it. I have some code but I\'m lost on how to continue as

3条回答
  •  离开以前
    2021-02-06 09:45

    Uri contentUri="You record video uri";
    
    try {
                                            Date date= new Date();
                                            android.text.format.DateFormat.format("yyyy-MM-dd_hh:mm:ss", date);
                                            String Video_DIRECTORY = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + getString(R.string.app_name) + "/video/";
                                            File storeDirectory = new File(Video_DIRECTORY);
    
                                            try {
                                                if (storeDirectory.exists() == false) {
                                                    storeDirectory.mkdirs();
                                                }
    
    
                                            } catch (Exception e) {
                                                e.printStackTrace();
    
                                            }
                                            File storeDirectory12 = new File(storeDirectory,date+".mp4");
                                            InputStream inputStream = getContentResolver().openInputStream(contentUri);
                                            FileOutputStream fileOutputStream = new FileOutputStream(storeDirectory12);
                                            copyStream(inputStream, fileOutputStream);
                                            fileOutputStream.close();
                                            inputStream.close();
                                        } catch (FileNotFoundException e) {
                                            Log.e("Exception", "" + e);
                                        } catch (IOException e) {
                                            Log.e("Exception", "" + e);
                                        }
    

提交回复
热议问题