Closed MuhammadAasharibNawshad closed 3 weeks ago
This is because in the demo app, we only set theMIME_TYPE
tovideo/mp4
:
private void setOutputPath() {
String filename = generateFileName();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
resolver = getContentResolver();
contentValues = new ContentValues();
contentValues.put(MediaStore.Video.Media.RELATIVE_PATH, "Movies/" + "HBRecorder");
contentValues.put(MediaStore.Video.Media.TITLE, filename);
contentValues.put(MediaStore.MediaColumns.DISPLAY_NAME, filename);
// Below you can see it is set to mp4
contentValues.put(MediaStore.MediaColumns.MIME_TYPE, "video/mp4");
mUri = resolver.insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, contentValues);
hbRecorder.setFileName(filename);
hbRecorder.setOutputUri(mUri);
}else{
createFolder();
hbRecorder.setOutputPath(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES) +"/HBRecorder");
}
}
I have modified the demo app to set the MIME_TYPE
depending on what output format was selected:
private void setOutputPath() {
String filename = generateFileName();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
resolver = getContentResolver();
contentValues = new ContentValues();
contentValues.put(MediaStore.Video.Media.RELATIVE_PATH, "Movies/" + "HBRecorder");
contentValues.put(MediaStore.Video.Media.TITLE, filename);
contentValues.put(MediaStore.MediaColumns.DISPLAY_NAME, filename);
contentValues.put(MediaStore.MediaColumns.MIME_TYPE, getMimeTypeForOutputFormat(output_format));
mUri = resolver.insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, contentValues);
hbRecorder.setFileName(filename);
hbRecorder.setOutputUri(mUri);
}else{
createFolder();
hbRecorder.setOutputPath(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES) +"/HBRecorder");
}
}
// Passing the MIME_TYPE to ContentValues() depending on what output format was selected
// This is just to demonstrate for the demo app - more can be added
private String getMimeTypeForOutputFormat(String outputFormat) {
String mimetype = "video/mp4";
switch (outputFormat) {
// We do not know what the devices DEFAULT (0) is
// For the sake of this demo app we will set it to mp4
case "0":
mimetype = "video/mp4";
break;
case "1":
mimetype = "video/mp4";
break;
case "2":
mimetype = "video/3gpp";
break;
case "3":
mimetype = "video/webm";
break;
default:
mimetype = "video/mp4";
break;
}
return mimetype;
}
Thanks for picking up on this and letting me know. This is now available in 3.0.6
Describe the bug The output format setting is not working and file is saved only in MP4 format even if I select other settings like THREE_GPP, WEBM etc.
Log No log needed
Can it be reproduced in demo app Yes
HBRecorder version 3.0.3
Device information
Screenshots NA