Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 22... Línea 22...
22
 */
22
 */
Línea 23... Línea 23...
23
 
23
 
24
import BaseClass from './base_recorder';
24
import BaseClass from './base_recorder';
25
import Modal from './modal';
25
import Modal from './modal';
-
 
26
import {component} from 'tiny_recordrtc/common';
-
 
27
import {convertMp3} from './convert_to_mp3';
Línea 26... Línea 28...
26
import {component} from 'tiny_recordrtc/common';
28
import {add as addToast} from 'core/toast';
-
 
29
 
-
 
30
export default class Audio extends BaseClass {
-
 
31
 
-
 
32
    // A mapping of MIME types to their corresponding file extensions.
-
 
33
    fileExtensions = {
-
 
34
        'audio/ogg': 'ogg',
-
 
35
        'audio/mp4': 'mp4',
-
 
36
        'audio/webm': 'webm',
27
 
37
    };
28
export default class Audio extends BaseClass {
38
 
29
    configurePlayer() {
39
    configurePlayer() {
Línea 30... Línea 40...
30
        return this.modalRoot.querySelector('audio');
40
        return this.modalRoot.querySelector('audio');
Línea 38... Línea 48...
38
 
48
 
39
            // Safari supports mp4.
49
            // Safari supports mp4.
40
            'audio/mp4;codecs=opus',
50
            'audio/mp4;codecs=opus',
41
            'audio/mp4;codecs=wav',
51
            'audio/mp4;codecs=wav',
-
 
52
            'audio/mp4;codecs=mp3',
-
 
53
 
-
 
54
            // Set webm as a fallback.
42
            'audio/mp4;codecs=mp3',
55
            'audio/webm;codecs=opus',
43
        ];
56
        ];
Línea 44... Línea 57...
44
    }
57
    }
45
 
58
 
46
    getRecordingOptions() {
59
    getRecordingOptions() {
-
 
60
        return {
47
        return {
61
            audioBitsPerSecond: parseInt(this.config.audiobitrate),
48
            audioBitsPerSecond: parseInt(this.config.audiobitrate),
62
            audioBitsPerSecondInKb: parseInt(this.config.audiobitrate / 1000),
Línea 49... Línea 63...
49
        };
63
        };
50
    }
64
    }
Línea 70... Línea 84...
70
    getFileName(prefix) {
84
    getFileName(prefix) {
71
        return `${prefix}-audio.${this.getFileExtension()}`;
85
        return `${prefix}-audio.${this.getFileExtension()}`;
72
    }
86
    }
Línea 73... Línea 87...
73
 
87
 
74
    getFileExtension() {
88
    getFileExtension() {
75
        if (window.MediaRecorder.isTypeSupported('audio/ogg')) {
89
        if (this.config.audiortcformat === 1) {
-
 
90
            return 'mp3';
-
 
91
        }
76
            return 'ogg';
92
 
77
        } else if (window.MediaRecorder.isTypeSupported('audio/mp4')) {
93
        const options = super.getParsedRecordingOptions(); // Call parent method.
-
 
94
        if (options?.mimeType) {
-
 
95
            const mimeType = options.mimeType.split(';')[0];
78
            return 'mp4';
96
            return this.fileExtensions[mimeType];
Línea 79... Línea 97...
79
        }
97
        }
80
 
98
 
81
        window.console.warn(`Unknown file type for MediaRecorder API`);
99
        window.console.warn(`Unknown file type for MediaRecorder API`);
Línea 86... Línea 104...
86
        return class extends Modal {
104
        return class extends Modal {
87
            static TYPE = `${component}/audio_recorder`;
105
            static TYPE = `${component}/audio_recorder`;
88
            static TEMPLATE = `${component}/audio_recorder`;
106
            static TEMPLATE = `${component}/audio_recorder`;
89
        };
107
        };
90
    }
108
    }
-
 
109
 
-
 
110
    async uploadRecording() {
-
 
111
        if (this.getFileExtension() === "mp3") {
-
 
112
            try {
-
 
113
                const options = this.getRecordingOptions();
-
 
114
                this.blob = await convertMp3(this.player.src, options.audioBitsPerSecondInKb);
-
 
115
                this.player.src = URL.createObjectURL(this.blob);
-
 
116
            } catch (error) {
-
 
117
                // Display a user-friendly error message
-
 
118
                const message = `MP3 conversion failed: ${error.message || 'Unknown error'}. Please try again.`;
-
 
119
                addToast(message, {type: 'error', delay: 6000});
-
 
120
 
-
 
121
                // Disable the upload button.
-
 
122
                this.setUploadButtonState(false);
-
 
123
 
-
 
124
                return;
-
 
125
            }
-
 
126
        }
-
 
127
 
-
 
128
        super.uploadRecording();
-
 
129
    }
91
}
130
}