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

217
Visualizações
Why does Html5 video player area react only on mouse click, but not on finger touch?

I am trying to make it so that I can use my finger (touch) anywhere on a video player to start and stop it.

However, I can only start and stop the video if I press the audio controls with the finger:

audiocontrols

Alternatively, I can click anywhere on the videoplayer with the mouse. This mouse click will start or stop the video.

I don't know if the problem is that a finger touch (unlike a mouse click) does not raise a certain event or if touching the video is generally not starting / stopping it, and I need a function for that.

Here is an example that I found. However, it's not working: When I click the video with the mouse, it shortly stops, then starts right again.

Thank you for any hint on what might be going on here and how to fix it.

<html>
<head><meta name="viewport" content="width=device-width">
</head>
<body>

<video onclick="playPause()" id="video_player" controls="controls" poster=""> 
    <source  id="video_mp4" src="file:///C:/Users/Kommunikation/Desktop/affen.mp4" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"' />
</video>    

<script>
var myVideo = document.getElementById("video_player");    
function playPause() { 
    if (myVideo.paused) 
        myVideo.play(); 
    else 
        myVideo.pause(); 
}
</script>

</body>
</html>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I got it:

I need to react on the ontouchstart (or ontouchend):

<html>
<head><meta name="viewport" content="width=device-width">
</head>
<body>

<video ontouchstart="playPause()" id="video1" controls="controls" poster=""> 
    <source  id="somevideoID" src="file:///C:/Users/Kommunikation/Desktop/affen.mp4" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"' />
</video>    

<script>
function playPause(e) {

  var myVideo = document.getElementById("video1");
  if (myVideo.paused) myVideo.play();
  else myVideo.pause();
}
</script>

</body>
</html>
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