Home > Mobile >  HTML-Page does not play video
HTML-Page does not play video

Time:09-13

I am creating a HTML-Page for my local PC for fun and want to implement a video player. I searched for how to do it and found something which I applied to my page:

<video width="400" controls>
  <source src="Videos/test.mp4" type="video/mp4"><source>
</video>

I even tried to embed the source attribute:

<video width="400" src="Videos/test.mp4" controls></video>

Both end up creating a video frame with play button but nothing is played. Even when I click on the play button nothing reacts to my click.

enter image description here

Does anyone unterstand why?

CodePudding user response:

You should check the DevTools (F12) network tab for any errors while fetching the video file. Probably your answer will be there.

Most likely, this has something to do with the file path you've entered in the [src] attribute.

From https://www.w3schools.com/tags/att_video_src.asp:

Possible values:

  • An absolute URL - points to another web site (like src="http://www.example.com/movie.ogg")
  • A relative URL - points to a file within a web site (like src="movie.ogg")

CodePudding user response:

Try this way it may be work if your src path not correct

Videos/test.mp4 => /Videos/test.mp4

  <video width="400" controls>
      <source src="/Videos/test.mp4" type="video/mp4"><source>
  </video>
  

CodePudding user response:

I think it's because you are using <source> tag twice. And you can't use an empty <source>. It should be like :

<video width="400" controls>
  <source src="Videos/test.mp4" type="video/mp4">
</video> 

reference : https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video

  • Related