JSFiddle - React, Tailwind, and code Playground

by juErik

HTML

<script src="https://www.webrtc-experiment.com/RecordRTC.js"></script>
            <section class="experiment">  
                <h2 class="header">Record Audio (both Chrome/Firefox)</h2>
			
                <div class="inner" style="height: 5em;">
                    <audio id="audio" autoplay controls></audio>
                    <button id="record-audio">Record</button>
                    <button id="stop-recording-audio" disabled>Stop</button>
                    <h2 id="audio-url-preview"></h2>
                </div>
            </section>

CSS

audio {
                vertical-align: bottom;
                width: 10em;
            }


            input {
                border: 1px solid #d9d9d9;
                border-radius: 1px;
                font-size: 2em;
                margin: .2em;
                width: 30%;
            }

JavaScript

function getByID(id) {
                    return document.getElementById(id);
                }

                var recordAudio = getByID('record-audio'),
                    stopRecordingAudio = getByID('stop-recording-audio');

                var audio = getByID('audio');


                var audioConstraints = {
                    audio: true,
                    video: false
                };



var audioStream;
                var recorder;

                recordAudio.onclick = function() {
                    if (!audioStream)
                        navigator.getUserMedia(audioConstraints, function(stream) {
                            if (window.IsChrome) stream = new window.MediaStream(stream.getAudioTracks());
                            audioStream = stream;

                            audio.src = URL.createObjectURL(audioStream);
                            audio.muted = true;
                            audio.play();

                            // "audio" is a default type
                            recorder = window.RecordRTC(stream, {
                                type: 'audio'
                            });
                            recorder.startRecording();
                        }, function() {
                        });
                    else {
                        audio.src = URL.createObjectURL(audioStream);
                        audio.muted = true;
                        audio.play();
                        if (recorder) recorder.startRecording();
                    }

                    window.isAudio = true;

                    this.disabled = true;
                    stopRecordingAudio.disabled = false;
                };


                stopRecordingAudio.onclick = function() {
                    this.disabled = true;
                    recordAudio.disabled = false;
                    audio.src = '';

                    if (recorder)
                        recorder.stopRecording(function(url) {
     ...