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

263
Views
I am using Web Audio API with React, but DecodeAudioData is not taking an ArrayBuffer to play a file

This code works well in Vanilla JS, but when in a component of React audioContext.decodeAudioData(buffer) returns the error:

"Uncaught (in promise) DOMException: The buffer passed to decodeAudioData contains an unknown content type." (It needs an arrayBuffer)

When logging the buffer I pass to the decoder, it is indeed an ArrayBuffer. I have tried creating the ArrayBuffer in different ways, such as using different file types but nothing has worked.

I built this following documentation and some examples, so far I think it might be an issue wit React.

If someone has a workaround or a solution, It would be awesome. Thanks for taking the time.

import { audioContext, primaryGainControl } from "../App";

const Channel = () => {
  /*console.log(audioContext);
  console.log(primaryGainControl);*/
  const [volume, setVolume] = useState(80);
  const channelGain = audioContext.createGain();
  channelGain.gain.setValueAtTime(0.8, 0);
  channelGain.connect(primaryGainControl);

  //Global variables
  var startTime = 0;
  var offsetToResume = 0;
  var pauseTime = 0;
  var isPlaying = false;
  var songSource = audioContext.createBufferSource();
  var rate = 1;
  var isPlaying = false;
  var FILE_URL = "271417__soneproject__hats-6.wav";


  const playAudio = async () => {
    if (isPlaying) return;
    channelGain.gain.setValueAtTime(volume / 100, audioContext.currentTime);
    const response = await fetch(FILE_URL);
    const buffer = await response.arrayBuffer();

    const songBuffer = await audioContext.decodeAudioData(buffer); 
//Here is where the error occurs ^ ^
    songSource = audioContext.createBufferSource();
    songSource.buffer = songBuffer;
    songSource.connect(channelGain);
    startTime = audioContext.currentTime;
    songSource.start(audioContext.currentTime, offsetToResume);
    isPlaying = true;
  };

...
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!