Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

199
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda