Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

265
Views
Web Audio API - Can't get simple audio to play

I'm trying to learn the Web Audio API from the MDN tutorial but even the most basic example — no modular synthesis, just playing a simple mp3 file — doesn't seem to work on my end.

I can see the dataset value being switched in the console, the play/pause on the controls change state, and in Firefox and Safari (but not in Chrome) the track locator even advances and the "playing" icon displayed on the browser tab.

(I've added the controls attribute to the audio tag just to have a progress indicator visible).

I can also download the file from the DOM controls and play it using the OS, and I've tried it with three different MP3 files. The computer's speakers are obviously working.

BTW, creating audio with oscillators and the AudioContext object works fine.

I'm out of ideas.

HTML

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <audio controls src="song.mp3"></audio>
    <button data-playing="false" role="switch" aria-checked="false">
        <span>Play/Pause</span>
    </button> 
    <script src="audio.js"></script>
</body>
</html>

JS

'use-strict'

const aCtx = new AudioContext();
const el = document.querySelector('audio');
const track = aCtx.createMediaElementSource(el);
const button = document.querySelector('button');

button.addEventListener('click', function() {
    console.log(this);
    
    if (aCtx.state === 'suspended') {
        aCtx.resume();
    }
    
    if (this.dataset.playing === 'false') {
        el.play();
        this.dataset.playing = 'true';
    } else {
        el.pause();
        this.dataset.playing = 'false';
    }
}, false);
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!