diff --git a/lib/editor/tiny/plugins/recordrtc/classes/constants.php b/lib/editor/tiny/plugins/recordrtc/classes/constants.php index 93f863488d5..14459c51de9 100644 --- a/lib/editor/tiny/plugins/recordrtc/classes/constants.php +++ b/lib/editor/tiny/plugins/recordrtc/classes/constants.php @@ -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]; } diff --git a/lib/editor/tiny/plugins/recordrtc/db/upgrade.php b/lib/editor/tiny/plugins/recordrtc/db/upgrade.php index d5a3076a463..f5946b3fa5e 100644 --- a/lib/editor/tiny/plugins/recordrtc/db/upgrade.php +++ b/lib/editor/tiny/plugins/recordrtc/db/upgrade.php @@ -45,6 +45,24 @@ function xmldb_tiny_recordrtc_upgrade($oldversion) { upgrade_plugin_savepoint(true, 2024042400, 'tiny', 'recordrtc'); } + if ($oldversion < 2024100701) { + // 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, 2024100701); + } + // Automatically generated Moodle v4.5.0 release upgrade line. // Put any upgrade step following this. diff --git a/lib/editor/tiny/plugins/recordrtc/lang/en/tiny_recordrtc.php b/lib/editor/tiny/plugins/recordrtc/lang/en/tiny_recordrtc.php index fc82a7b502d..a07e4cc1363 100644 --- a/lib/editor/tiny/plugins/recordrtc/lang/en/tiny_recordrtc.php +++ b/lib/editor/tiny/plugins/recordrtc/lang/en/tiny_recordrtc.php @@ -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.'; diff --git a/lib/editor/tiny/plugins/recordrtc/settings.php b/lib/editor/tiny/plugins/recordrtc/settings.php index b96e7b1166d..4dda79110b6 100644 --- a/lib/editor/tiny/plugins/recordrtc/settings.php +++ b/lib/editor/tiny/plugins/recordrtc/settings.php @@ -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. diff --git a/lib/editor/tiny/plugins/recordrtc/version.php b/lib/editor/tiny/plugins/recordrtc/version.php index f852957a41c..a228211e6c0 100644 --- a/lib/editor/tiny/plugins/recordrtc/version.php +++ b/lib/editor/tiny/plugins/recordrtc/version.php @@ -24,6 +24,6 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2024100700; +$plugin->version = 2024100701; $plugin->requires = 2024100100; $plugin->component = 'tiny_recordrtc';