Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="wrapper">
  <div class="audio-wrapper">
    <audio src="" controls class="js-audio audio"></audio>
  </div>

  <div class="toolbar">
    <button class="js-start button button--start">Start</button>
    <button class="js-stop button button--stop">Stop</button>
  </div>
</div>
              
            
!

CSS

              
                $white: #ffffff;
$grey: #E5E5E5;
$grey-dark: #B5B4B9;

$green: #6ABB5C;
$blue: #4FABE4;

body {
  background: $white;
}

.wrapper {
  padding: 2rem;
}

.audio-wrapper {
  margin: 0 0 2rem 0;
}

.audio {
  width: 100%;
  
  &::-webkit-media-controls-panel {
    background: white;
  }
}

.toolbar {
  text-align: center
}

.button {
  transition: all .4s ease-in-out;
  
  position: inline-block;
  padding: .6rem 1rem;
  
  background: $white;
  
  border: 1px solid $grey;
  border-radius: 0;
  outline: none;
  
  text-transform: uppercase;
  color: $grey-dark;
  
  &--start:hover {
    background: $green;
    
    border-color: darken($green, 5);
    
    color: $white;
  }
    
  &--stop:hover {
    background: $blue;
    
    border-color: darken($blue, 5);
    
    color: $white;
  }
}


              
            
!

JS

              
                // We'll save all chunks of audio in this array.
const chunks = [];

// We will set this to our MediaRecorder instance later.
let recorder = null;

// We'll save some html elements here once the page has loaded.
let audioElement = null;
let startButton = null;
let stopButton = null;

/**
 * Save a new chunk of audio.
 * @param  {MediaRecorderEvent} event 
 */
const saveChunkToRecording = (event) => {
    chunks.push(event.data);
};

/**
 * Save the recording as a data-url.
 * @return {[type]}       [description]
 */
const saveRecording = () => {
    const blob = new Blob(chunks, {
        type: 'audio/mp4; codecs=opus'
    });
    const url = URL.createObjectURL(blob);

    audioElement.setAttribute('src', url);
};

/**
 * Start recording.
 */
const startRecording = () => {
    recorder.start();
};

/**
 * Stop recording.
 */
const stopRecording = () => {
    recorder.stop();
};


// Wait until everything has loaded
(function() {
    audioElement = document.querySelector('.js-audio');
    startButton = document.querySelector('.js-start');
    stopButton = document.querySelector('.js-stop');
    
    // We'll get the user's audio input here.
    navigator.mediaDevices.getUserMedia({
        audio: true // We are only interested in the audio
    }).then(stream => {
        // Create a new MediaRecorder instance, and provide the audio-stream.
        recorder = new MediaRecorder(stream);

        // Set the recorder's eventhandlers
        recorder.ondataavailable = saveChunkToRecording;
        recorder.onstop = saveRecording;
    });

    // Add event listeners to the start and stop button
    startButton.addEventListener('mouseup', startRecording);
    stopButton.addEventListener('mouseup', stopRecording);
})();

              
            
!
999px

Console