I need to share my mp4 video file generated by my app, which acquires name with a ( System.currentTimeMillis /1000
). the share action must choose that last generated file to share it in social networks.
I leave the initRecorder
method which generates the mp4 file and the current compartir
method.
private final String MAIN_FOLDER = "DCApp/";
private final String RUTA_VIDEO = MAIN_FOLDER + "DCvideos";
private void initRecorder(){
String videoName = "DC_" + (System.currentTimeMillis() / 1000) + ".mp4";
File fileVideo = new File(Environment.getExternalStorageDirectory(), VIDEO_RUTE);
try{
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mMediaRecorder.setOutputFile(fileVideo + videoName);
mMediaRecorder.setVideoSize(DISPLAY_WIDTH, DISPLAY_HEIGHT);
mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mMediaRecorder.setVideoEncodingBitRate(512 * 1000);
mMediaRecorder.setVideoFrameRate(30);
int rotation = getWindowManager().getDefaultDisplay().getRotation();
int orientation = ORIENTATIONS.get(rotation + 90);
mMediaRecorder.setOrientationHint(orientation);
mMediaRecorder.prepare();
}catch(IOException e){
e.printStackTrace();
}
}
Share method:
private void share() {
Intent share = new Intent(android.content.Intent.ACTION_SEND);
share.putExtra(Intent.ACTION_PICK, MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
share.setType("video/");
startActivity(Intent.createChooser(share, "share via:"));
}