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

193
Visualizações
How do I detect if a browser does not support changing html audio volume?

So I recently discovered that iOS Safari does not allow volume to be controlled through javascript on audio elements. Fine. But how do I detect it to not show a control for it in my custom player?

From their documentation:

On iOS devices, the audio level is always under the user’s physical control. The volume property is not settable in JavaScript. Reading the volume property always returns 1.

So I thought I'd extend some trust to Apple's documentation (which is always a mistake), and believe them when they say Reading the volume property always returns 1. So I created this function that simply changes the volume of an audio element and then checks if it changed, and changes it back if not.

Turns out the documentation was wrong, and actually, at least in synchronous code, it momentarily stays at 0.9 and so this function always returns true.

function isVolumeChangeable(audioElement) {
  const lastSetting = audioElement.volume
  audioElement.volume = 0.9
  const changed = audioElement.volume == 0.9 // Supposed to equal one in iOS
  audioElement.volume = lastSetting // Change it back
  return changed
}

Now I can be really dirty and put some kind of timeout in there, but there has to be a better way.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Why not use navigator.userAgent (docs: https://developer.mozilla.org/en-US/docs/Web/API/Navigator/userAgent) and do some regex to detect iOS / Safari?

about 4 years ago · Juan Pablo Isaza Relatório
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