Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

html5 video does not play from localhost

The mp4 video does not play from localhost.

But mp3 audio works.

i.e.

Following code for playing video (stored as C:\inetpub\wwwroot\video\testVideo.html) does not work when accessed through (http://localhost/video/testVideo.html)

    <!DOCTYPE html> 
    <html>
    <body>
    <video width="400" controls>
      <source src="video.mp4" type="video/mp4">
      Your browser does not support HTML5 video.
    </video>
    </body> 
    </html>

But, following code for playing audio (C:\inetpub\wwwroot\audio\testAudio.html) works when accessed through (http://localhost/audio/testAudio.html)

    <!DOCTYPE html> 
    <html>
    <body> 
    <audio width="400" controls>
      <source src="audip.mp3" type="audio/mp3">
      Your browser does not support HTML5 video.
    </audio>
    </body> 
    </html>

However, they both work when webpage is launched by double clicking on html file i.e. webpage is accessed through (file:///C:/inetpub/wwwroot/audio/testAudio.html) or (file:///C:/inetpub/wwwroot/video/testVideo.html)

Please explain what am I doing wrong. And how to make video play from localhost.

I am using following browsers:

IE 11.0
Chrome 44.0
Firefox 40.0
like image 914
Prasoon Avatar asked Oct 31 '22 21:10

Prasoon


1 Answers

I finally figured it out.

The video doesn't play via localhost, because IIS localhost in Windows doesn't contain MIME type entry (video/mp4) for .mp4 file format.

To make this work, a MIME type entry should be added in following way:

  1. Open IIS Manager
  2. Select your machine from Connection panel
  3. From middle panel, double-click 'MIME Types'
  4. Right-click on the list and select 'Add' option
  5. Add file extension and MIME type e.g. for MP4 videos, file extension: .mp4 and MIME type: 'video/mp4'

Thats it.

Now refresh your page and Bingo!. It works.

like image 131
Prasoon Avatar answered Nov 08 '22 07:11

Prasoon