Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

219
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda