Reputation: 31
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 ?
Upvotes: 1
Views: 1439
Reputation: 31
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.
Upvotes: 2