1 |
efrain |
1 |
// This file is part of Moodle - http://moodle.org/
|
|
|
2 |
//
|
|
|
3 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
4 |
// it under the terms of the GNU General Public License as published by
|
|
|
5 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
6 |
// (at your option) any later version.
|
|
|
7 |
//
|
|
|
8 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
9 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
10 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
11 |
// GNU General Public License for more details.
|
|
|
12 |
//
|
|
|
13 |
// You should have received a copy of the GNU General Public License
|
|
|
14 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
15 |
|
|
|
16 |
/**
|
|
|
17 |
* Tiny Record RTC - audio recorder configuration.
|
|
|
18 |
*
|
|
|
19 |
* @module tiny_recordrtc/audio_recorder
|
|
|
20 |
* @copyright 2022 Stevani Andolo <stevani@hotmail.com.au>
|
|
|
21 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
22 |
*/
|
|
|
23 |
|
|
|
24 |
import BaseClass from './base_recorder';
|
|
|
25 |
import Modal from './modal';
|
|
|
26 |
import {component} from 'tiny_recordrtc/common';
|
|
|
27 |
|
|
|
28 |
export default class Audio extends BaseClass {
|
|
|
29 |
configurePlayer() {
|
|
|
30 |
return this.modalRoot.querySelector('audio');
|
|
|
31 |
}
|
|
|
32 |
|
|
|
33 |
getSupportedTypes() {
|
|
|
34 |
return [
|
|
|
35 |
// Firefox supports webm and ogg but Chrome only supports ogg.
|
|
|
36 |
// So we use ogg to maximize the compatibility.
|
|
|
37 |
'audio/ogg;codecs=opus',
|
|
|
38 |
|
|
|
39 |
// Safari supports mp4.
|
|
|
40 |
'audio/mp4;codecs=opus',
|
|
|
41 |
'audio/mp4;codecs=wav',
|
|
|
42 |
'audio/mp4;codecs=mp3',
|
|
|
43 |
];
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
getRecordingOptions() {
|
|
|
47 |
return {
|
|
|
48 |
audioBitsPerSecond: parseInt(this.config.audiobitrate),
|
|
|
49 |
};
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
getMediaConstraints() {
|
|
|
53 |
return {
|
|
|
54 |
audio: true,
|
|
|
55 |
};
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
getRecordingType() {
|
|
|
59 |
return 'audio';
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
getTimeLimit() {
|
|
|
63 |
return this.config.audiotimelimit;
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
getEmbedTemplateName() {
|
|
|
67 |
return 'tiny_recordrtc/embed_audio';
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
getFileName(prefix) {
|
|
|
71 |
return `${prefix}-audio.${this.getFileExtension()}`;
|
|
|
72 |
}
|
|
|
73 |
|
|
|
74 |
getFileExtension() {
|
|
|
75 |
if (window.MediaRecorder.isTypeSupported('audio/ogg')) {
|
|
|
76 |
return 'ogg';
|
|
|
77 |
} else if (window.MediaRecorder.isTypeSupported('audio/mp4')) {
|
|
|
78 |
return 'mp4';
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
window.console.warn(`Unknown file type for MediaRecorder API`);
|
|
|
82 |
return '';
|
|
|
83 |
}
|
|
|
84 |
|
|
|
85 |
static getModalClass() {
|
|
|
86 |
return class extends Modal {
|
|
|
87 |
static TYPE = `${component}/audio_recorder`;
|
|
|
88 |
static TEMPLATE = `${component}/audio_recorder`;
|
|
|
89 |
};
|
|
|
90 |
}
|
|
|
91 |
}
|