1

From this topic HTML5 audio element with dynamic source I use this part of code very well:

<audio id="player" controls="controls" autoplay="true" loop="loop"><source   src="song.php" type="audio/mpeg" /> </audio>

song.php:

$file = "something.mp3";
header("Content-Type:audio/mpeg");
header("Content-LEngth:".filesize($file));
readfile($file);

Now I want to do the same with videos mp4.

<video autoplay="true" controls src="video.php" type="video/mp4"></video>

video.php:

$file = "something.mp4";
header("Content-Type:video/mp4");
header("Content-LEngth:".filesize($file));
readfile($file);

but this doesn't work, the video isn't playing. Any idea how I can prevent to deliver the URL to the video ?

Community
  • 1
  • 1
Uwe S.
  • 31
  • 4
  • 1
    Are you sure that something.mp4 file exist in the same directory where video.php is? If yes - is it properly encoded? Are there any JS errors in the DEV console? – V.Vachev Nov 25 '16 at 12:33
  • yes, the file exists and is playable. – Uwe S. Nov 25 '16 at 12:44
  • do you think it must work ? the complete code is a little bit more complicated, maybe I must serach at a other place ? – Uwe S. Nov 25 '16 at 12:50
  • Could you please open DEV console (F12) and check for any JS errors. Also, does the Video element show some error? Add some text – V.Vachev Nov 25 '16 at 12:51
  • the only errormsg in DEV is Http 500 and the controls in the videobox are only short visible and then hidden. The erromsg is : the video-format ore Mimetype not supported. – Uwe S. Nov 25 '16 at 13:23
  • The error is probably in your video.php file. Could you enable the errors with these lines at the beginning of the file: error_reporting(E_ALL); ini_set('display_errors', 1); – V.Vachev Nov 25 '16 at 13:31

1 Answers1

2

I stripped out my testcode:

<audio controls ><source src="content_de/media.php?t=1&f=something.mp3"   type="audio/mpeg" /></audio>
<br><br>
<video autoplay="true" controls src="content_de/media.php?t=2&f=something.mp4" type="video/mp4"></video>

and the media.php:

$file = 'C:\\media\\de\\w\\' . $f;
if (file_exists($file)) {
   if ($t == 1) {

    header("Content-Type:audio/mpeg");
    header("Content-Length:".filesize($file));
    readfile($file);
    exit;
}



if ($t == 2) {
    header("Content-Type:video/mp4");

    header("Content-Length:".filesize($file));
    readfile($file);
    exit;
 }
}

the audio is playing well, then video not.

Uwe S.
  • 31
  • 4