MDL-83570 tiny_recordrtc: Turn the audio bitrate input to Select field

The current code may have a bug. If users set the audio bit rate to
a non-supported value, such as 1000,
Firefox will display an error in the console,
while Chrome will create the recorded audio file successfully,
but it will have no sound. I tested this on Ubuntu 24.04.

The minimum bit rate threshold varies depending on the audio format.
During my tests with Firefox version 131.0.3, which uses
the audio/Ogg format, I found that the minimum supported value
is 24000. In Chrome 129.0.6668.70, which uses the audio/MP4 format,
the minimum supported value is 2400.

Due to these differences, I decided to change the input from
a text field to a select field, offering options that support both
Ogg and MP4 audio formats.

The database conversion for the old value has been provided in
the lib/db/upgrade.php. The script will find the closest match to
the current data and update it accordingly.
This commit is contained in:
meirzamoodle 2024-10-29 07:00:24 +07:00
parent 269a8a8a1b
commit 392ed9c627
5 changed files with 35 additions and 3 deletions

View File

@ -39,4 +39,7 @@ class constants {
/** @var string TINYRECORDRTC_SCREEN_FHD The Full-HD screen-sharing resolution. */
public const TINYRECORDRTC_SCREEN_FHD = '1920,1080';
/** @var array TINYRECORDRTC_AUDIO_BITRATES The audio bitrate options. */
public const TINYRECORDRTC_AUDIO_BITRATES = [24000, 32000, 48000, 64000, 96000, 128000, 160000, 192000, 256000, 320000];
}

View File

@ -45,6 +45,24 @@ function xmldb_tiny_recordrtc_upgrade($oldversion) {
upgrade_plugin_savepoint(true, 2024042400, 'tiny', 'recordrtc');
}
if ($oldversion < 2024112000) {
// The input bitrate to be converted.
$currentbitrate = get_config('tiny_recordrtc', 'audiobitrate');
// Supported bitrates.
$supportedbitrates = \tiny_recordrtc\constants::TINYRECORDRTC_AUDIO_BITRATES;
// Find the nearest value.
usort($supportedbitrates, fn($a, $b) => abs($currentbitrate - $a) <=> abs($currentbitrate - $b));
$nearestbitrate = $supportedbitrates[0];
// Update the bitrate setting with the nearest supported bitrate.
set_config('audiobitrate', $nearestbitrate, 'tiny_recordrtc');
// Main savepoint reached.
upgrade_main_savepoint(true, 2024112000);
}
// Automatically generated Moodle v4.5.0 release upgrade line.
// Put any upgrade step following this.

View File

@ -54,6 +54,7 @@ $string['gumtype'] = 'Tried to get stream from the webcam/microphone/screen, but
$string['gumtype_title'] = 'No constraints specified';
$string['insecurealert'] = 'Your browser might not allow this plugin to work unless it is used either over HTTPS or from localhost.';
$string['insecurealert_title'] = 'Insecure connection!';
$string['kbrate'] = '{$a} kb/s';
$string['maxfilesizehit'] = 'You have reached the maximum size limit for file uploads.';
$string['maxfilesizehit_title'] = 'Recording stopped';
$string['norecordingfound'] = 'Something has gone wrong. Nothing has been recorded.';

View File

@ -61,8 +61,18 @@ if ($ADMIN->fulltree) {
// Audio bitrate.
$name = get_string('audiobitrate', 'tiny_recordrtc');
$desc = get_string('audiobitrate_desc', 'tiny_recordrtc');
$default = '128000';
$setting = new admin_setting_configtext('tiny_recordrtc/audiobitrate', $name, $desc, $default, PARAM_INT, 8);
$options = [];
foreach (\tiny_recordrtc\constants::TINYRECORDRTC_AUDIO_BITRATES as $rate) {
$kbrate = $rate / 1000;
$options[$rate] = get_string('kbrate', 'tiny_recordrtc', $kbrate);
}
$setting = new admin_setting_configselect(
name: 'tiny_recordrtc/audiobitrate',
visiblename: $name,
description: $desc,
defaultsetting: \tiny_recordrtc\constants::TINYRECORDRTC_AUDIO_BITRATES[5],
choices: $options,
);
$settings->add($setting);
// Video bitrate.

View File

@ -24,6 +24,6 @@
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2024100700;
$plugin->version = 2024112000;
$plugin->requires = 2024100100;
$plugin->component = 'tiny_recordrtc';