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

216
Views
Play sound when the user get message

I am making a web app where the users can chat with each other. I want, when the user receives a message, to play a sound to notify the user.

First, I use the way of playing the sound

import messageNotificationSound from 'src/assets/MessageNotification.mp3';
const audio = new Audio(sound)
audio.play()

I got the following error

DOMException: Failed to load because no supported source was found

This error is that I can't play a sound if the user is not interacting with the site. But you can solve it by giving the site sound permissions. So I solved the problem on localhost and pushed to the main site. But on the main site, it always fails also when the user is already interact with the site and the sound permissions are set to always. I got the same error.

I also use npm use-sound and it works on localhost, but not on the main site. It also doesn't throw any errors.

The way that I use use-sound:

import messageNotificationSound from 'src/assets/MessageNotification.mp3';
import useSound from 'use-sound';
const [play] = useSound(messageNotificationSound);
play();

Does anyone know how to solve this problem or have any suggestion? Thanks

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!