record

India’s cotton and pulses farmers shift to paddy, set to produce record 120 million tonnes rice

Area under paddy this year surged to record 43.37 million hectares (mh) from 40.73 mh year-ago.




record

Diwali, rising disposable income lifts jet fuel consumption in October to second highest on record

Diesel and petrol consumption rise during the month




record

Mangaluru International Airport records highest-ever passenger and air traffic movements in October 2024

The airport logged 1,538 air traffic movements, significantly up from 1,433 in September 2024




record

For the sake of record

Choirmaster Christopher Sherwood talks about his passion for collecting LP records and his love for music




record

Ludo platform Zupee hits record 100 million users, 6.6 billion gameplays




record

Ludo platform Zupee hits record 100 million users, 6.6 billion gameplays




record

India's solar product exports record over 20-fold jump to $2 bn in last 2 years




record

Two friends and their track of records

Mohammed Ameen and Mohammed Jaseel, Plus Two students from KKM Higher Secondary School, Cheekkode in Malappuram, contested the same event in the previous edition and finished exactly in the same positions




record

Record breaking suspension of 146 MPs: Which States and parties affected most | Data

Tamil Nadu, Kerala, and West Bengal are most impacted by the suspensions




record

JIPMER closure for Ram temple ceremony | Madras HC records emergency services will not be disrupted

JIPMER in Puducherry will be closed until 2:30 p.m. due to the consecration of Ram temple in Uttar Pradesh’s Ayodhya




record

People of Srinagar remain reluctant voters as district records 29.24% turnout

Srinagar district’s poll percentage was 27.9% in the 2014 Assembly election and recorded 29.24% this time; J&K Chief Electoral Officer says Srinagar saw an increase of 5% compared to voter turnout of the recent Lok Sabha polls



  • Jammu and Kashmir Assembly

record

Raja wins men’s 61kg with record lifts




record

Japan’s record number of women MPs still a minority

Japan ranks 118th of 146 in the 2024 World Economic Forum’s Global Gender Gap report




record

613: Recording Live Music, WebC, Open Source, & WordPress Studio

Chris bought recording gear off an Instagram ad, our thoughts on WebC, CodePen upgrades Yarn, thoughts on the commercial value of open source, Automattic releases an app to install WordPress locally, IBM buys Hashicorp, income tax software, and a hack for getting Safari to respect background colors used in a pseudo selector.




record

A Match of Many Records

The first One-Day International between India and Sri Lanka witnessed important milestones being set and new records being made.




record

Kohli surpasses Dravid's run record!

Virat Kohli surpassed Rahul Dravid to become the second highest run-scorer for India in international cricket.




record

Jet turns around with record Rs 1,212-cr. net profit




record

Debt private placements hit record high of Rs. 4,92,000 crore in FY16

Total mobilisation six per cent higher than previous financial year




record

Hyundai Motor India's record ₹27,870 crore IPO fully subscribed

The ₹27,870 crore initial share sale got bids for 14,07,68,187 shares against 9,97,69,810 shares on offer, translating into 1.41 times the subscription, as per NSE data till 13:21 hours




record

Building a Dictaphone Using Media Recorder and getUserMedia

Chris Mills brushes up his shorthand and shows how the MediaStream Recording API in modern browsers can be used to capture audio directly from the user’s device. Inching ever closer to the capabilities of native software, it truly is an exciting time to be a web developer.


The MediaStream Recording API makes it easy to record audio and/or video streams. When used with MediaDevices.getUserMedia(), it provides an easy way to record media from the user’s input devices and instantly use the result in web apps. This article shows how to use these technologies to create a fun dictaphone app.

A sample application: Web Dictaphone

To demonstrate basic usage of the MediaRecorder API, we have built a web-based dictaphone. It allows you to record snippets of audio and then play them back. It even gives you a visualisation of your device’s sound input, using the Web Audio API. We’ll just concentrate on the recording and playback functionality in this article, for brevity’s sake.

You can see this demo running live, or grab the source code on GitHub. This has pretty good support on modern desktop browsers, but pretty patchy support on mobile browsers currently.

Basic app setup

To grab the media stream we want to capture, we use getUserMedia(). We then use the MediaRecorder API to record the stream, and output each recorded snippet into the source of a generated <audio> element so it can be played back.

We’ll first declare some variables for the record and stop buttons, and the <article> that will contain the generated audio players:

const record = document.querySelector('.record');
const stop = document.querySelector('.stop');
const soundClips = document.querySelector('.sound-clips');

Next, we set up the basic getUserMedia structure:

if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
   console.log('getUserMedia supported.');
   navigator.mediaDevices.getUserMedia (
      // constraints - only audio needed for this app
      {
         audio: true
      })

      // Success callback
      .then(function(stream) {

      })

      // Error callback
      .catch(function(err) {
         console.log('The following `getUserMedia` error occured: ' + err);
      }
   );
} else {
   console.log('getUserMedia not supported on your browser!');
}

The whole thing is wrapped in a test that checks whether getUserMedia is supported before running anything else. Next, we call getUserMedia() and inside it define:

  • The constraints: Only audio is to be captured for our dictaphone.
  • The success callback: This code is run once the getUserMedia call has been completed successfully.
  • The error/failure callback: The code is run if the getUserMedia call fails for whatever reason.

Note: All of the code below is found inside the getUserMedia success callback in the finished version.

Capturing the media stream

Once getUserMedia has created a media stream successfully, you create a new Media Recorder instance with the MediaRecorder() constructor and pass it the stream directly. This is your entry point into using the MediaRecorder API — the stream is now ready to be captured into a <Blob>, in the default encoding format of your browser.

const mediaRecorder = new MediaRecorder(stream);

There are a series of methods available in the MediaRecorder interface that allow you to control recording of the media stream; in Web Dictaphone we just make use of two, and listen to some events. First of all, MediaRecorder.start() is used to start recording the stream once the record button is pressed:

record.onclick = function() {
  mediaRecorder.start();
  console.log(mediaRecorder.state);
  console.log("recorder started");
  record.style.background = "red";
  record.style.color = "black";
}

When the MediaRecorder is recording, the MediaRecorder.state property will return a value of “recording”.

As recording progresses, we need to collect the audio data. We register an event handler to do this using mediaRecorder.ondataavailable:

let chunks = [];

mediaRecorder.ondataavailable = function(e) {
  chunks.push(e.data);
}

Last, we use the MediaRecorder.stop() method to stop the recording when the stop button is pressed, and finalize the Blob ready for use somewhere else in our application.

stop.onclick = function() {
  mediaRecorder.stop();
  console.log(mediaRecorder.state);
  console.log("recorder stopped");
  record.style.background = "";
  record.style.color = "";
}

Note that the recording may also stop naturally if the media stream ends (e.g. if you were grabbing a song track and the track ended, or the user stopped sharing their microphone).

Grabbing and using the blob

When recording has stopped, the state property returns a value of “inactive”, and a stop event is fired. We register an event handler for this using mediaRecorder.onstop, and construct our blob there from all the chunks we have received:

mediaRecorder.onstop = function(e) {
  console.log("recorder stopped");

  const clipName = prompt('Enter a name for your sound clip');

  const clipContainer = document.createElement('article');
  const clipLabel = document.createElement('p');
  const audio = document.createElement('audio');
  const deleteButton = document.createElement('button');

  clipContainer.classList.add('clip');
  audio.setAttribute('controls', '');
  deleteButton.innerHTML = "Delete";
  clipLabel.innerHTML = clipName;

  clipContainer.appendChild(audio);
  clipContainer.appendChild(clipLabel);
  clipContainer.appendChild(deleteButton);
  soundClips.appendChild(clipContainer);

  const blob = new Blob(chunks, { 'type' : 'audio/ogg; codecs=opus' });
  chunks = [];
  const audioURL = window.URL.createObjectURL(blob);
  audio.src = audioURL;

  deleteButton.onclick = function(e) {
    let evtTgt = e.target;
    evtTgt.parentNode.parentNode.removeChild(evtTgt.parentNode);
  }
}

Let’s go through the above code and look at what’s happening.

First, we display a prompt asking the user to name their clip.

Next, we create an HTML structure like the following, inserting it into our clip container, which is an <article> element.

<article class="clip">
  <audio controls></audio>
  <p>_your clip name_</p>
  <button>Delete</button>
</article>

After that, we create a combined Blob out of the recorded audio chunks, and create an object URL pointing to it, using window.URL.createObjectURL(blob). We then set the value of the <audio> element’s src attribute to the object URL, so that when the play button is pressed on the audio player, it will play the Blob.

Finally, we set an onclick handler on the delete button to be a function that deletes the whole clip HTML structure.

So that’s basically it — we have a rough and ready dictaphone. Have fun recording those Christmas jingles! As a reminder, you can find the source code, and see it running live, on the MDN GitHub.


This article is based on Using the MediaStream Recording API by Mozilla Contributors, and is licensed under CC-BY-SA 2.5.


About the author

Chris Mills manages the MDN web docs writers’ team at Mozilla, which involves spreadsheets, meetings, writing docs and demos about open web technologies, and occasional tech talks at conferences and universities. He used to work for Opera and W3C, and enjoys playing heavy metal drums and drinking good beer.

More articles by Chris




record

Record profits: PNB Q2 consolidated net zooms 137% at ₹4,714 crore

On a standalone basis, PNB’s net profit for the quarter under review increased 145 per cent to ₹4,303 crore (₹1,756 crore)



  • Money &amp; Banking

record

UPI sets new record, transactions rise to 16.58 billion in October

Festival season spending aided the 45 per cent y-o-y rise in October UPI transactions



  • Money &amp; Banking

record

Bitcoin hits record high, soars above $75000 amid US election results

Industry experts attribute surge to substantial inflows into exchange-traded funds (ETFs), increased speculation surrounding the election outcomes




record

2,500 online courses in two years, a record feat by 51-year-old Srikakulam man

He wanted to highlight the need for students to acquire more knowledge and the availability of abundant free resources, says M.V.V.S. Sastry




record

Deepavali: KSRTC sets record with ₹5 crore in online ticket sales; 85,462 bookings in a day, highest since 2006 launch

According to KSRTC officials, major routes that saw high demand included popular destinations from Bengaluru such as Davangere, Mysuru, Hubballi, Tirupathi, Shivamogga, and Kalaburagi 




record

India’s retail equity investment cult rises to a new high amid record FPI outflows




record

Bitcoin has topped $87,000 for a new record high. What to know about crypto’s post-election rally

As money continues to pour into crypto following Donald Trump’s election victory, bitcoin has climbed to yet another record high




record

Bengaluru residential property micromarkets witness record hike in prices: Report

Prices in Bagaluru in North Bengaluru have surged by nearly 90 per cent in the past five years, while Whitefield has seen an 80 per cent rise in prices




record

Godrej Properties achieves record bookings of ₹5,200 crore in Q2 FY25

Godrej Properties witnessed an 89% increase in bookings year-on-year in the first half of FY25, amounting to ₹13,800 crore, surpassing its full-year booking guidance’s halfway mark and its previous annual bookings in FY23




record

A tool to record history

Kishore Nagappa, the sculptor behind statues for the likes of Jawaharlal Nehru, Ambedkar, Sathyamurthi, Muthuramalinga Devar and the most recent one of Pennycuick




record

Amit Shah calls Madhya Pradesh ‘lungs of Bharat’ as Indore sets world record by planting 11 lakh saplings

Amit Shah said that Madhya Pradesh contributes 12% of the nation’s forest cover and termed the State as the ‘lungs of Bharat’




record

My records not under threat for now, says Usain Bolt

Usain Bolt’s superhuman effort of 9.58 seconds (100m) and 19.19 seconds (200m) at the 2009 World Championships in Berlin have not been threatened ever since.




record

Deepthi Jeevanji wins gold with world record time in 400m T20 class in World Para Championships

Deepthi smashed American Breanna Clark's earlier world record of 55.12 seconds set during last year's edition of the championships in Paris




record

Asian Relays: Indian mixed 4x400m team sets National record

The timing puts India in the 21st place in the Road to Paris list of World Athletics while the aim was to be either in the 15th or 16th spot




record

Athletics: Chebet breaks 10,000m record, Kerr beats Ingebrigtsen

Chebet clocked 28 minutes 54.14 seconds, taking nearly seven seconds off the previous world record set by Ethiopian Letesenbet Gidey three years ago to qualify for the event at the Paris Olympics.




record

Indian GP: Yugendran leaps to a new meet record in men’s pole vault

Baranica secures the gold in women’s event; Vithya Ramraj claims the women’s 400m hurdles title; Abha bags the shot put top spot




record

Gulveer breaks Sable’s 5000m National record




record

Sprint hurdler Kiran breaks Maymon’s under-18 National record




record

Avinash Sable overwrites own meet record, Kushare consolidates Paris spot

The national record holder Avinash Sable, who has already attained the Paris Olympic qualifying standard, clocked 8:31.75 to overwrite his own previous meet record of 8:33.19, set five years ago in Lucknow.




record

Inter-State athletics | Tejas wins men’s hurdles with a new meet record




record

Ukraine's Mahuchikh breaks 1987 women's high jump world record

The Ukrainian outperformed the world indoor champion, Australia's Nicola Olyslagers, with both competitors clearing the 2.01 metre height on their second attempts




record

Paralympics 2024: Aim is to win gold with a new world record, says javelin thrower Sumit Antil

Sumit Antil along with Bhagyashree Jadhav will be Indian flag bearer at the opening ceremony of the Paralympics Games to be held from August 28 to September 8.




record

Paralympic Games: Praveen Kumar strikes gold in T64 high jump with Asian record

The country has so far won six gold, nine silver and 11 bronze medals to achieve its best-ever haul at a single edition of the Paralympic Games




record

South Asian Junior meet | Siddharth, Pooja and Abinaya break meet records




record

Poorva wins triple jump gold with meet record; men’s pole vault final postponed as pit reaches late




record

Athletics | Jyoti, Manna and Nayak set new meet records




record

Kujur betters own meet record in 200m; Puneet wins 5,000m; Moumita takes home long jump gold

Altogether four new meet records were set on the concluding day.




record

Arjun on a record-breaking spree, sprint double for Ashlin




record

Rabada breaks Waqar's Test record in Dhaka Test

Rabada reaches new milestone as Proteas take control over Bangladesh, on the opening day of the first Test against Bangladesh.




record

US spends record $17.9 billion on military aid to Israel since October 7

At least 1,400 people in Lebanon, including Hezbollah fighters and civilians, have been killed since Israel greatly expanded its strikes in that country in late September