Files
streamshifter/index.php
2021-10-15 21:13:18 -07:00

79 lines
2.4 KiB
PHP

<html>
<head>
<title>Live Audio and Podcasts</title>
<meta name="viewport" content="width=320">
<script src="mediaelement/build/jquery.js"></script>
<script src="mediaelement/build/mediaelement-and-player.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script>
<link rel="stylesheet" href="mediaelement/build/mediaelementplayer.min.css" />
<script type="text/javascript">
function LoadAudio(file)
{
document.getElementById("player").style.visibility="visible";
document.getElementById("video").style.visibility="hidden";
document.getElementById("player").innerHTML="<audio src=\"audio/"+file+"\" type=\"audio/m4a\" controls=\"controls\" width=\"500px\" />";
document.getElementById("filename").innerHTML=file;
$('audio').mediaelementplayer();
}
function LoadM3U8(file)
{
document.getElementById("player").style.visibility="hidden";
document.getElementById("video").style.visibility="visible";
var video=document.getElementById("video");
if (Hls.isSupported())
{
var hls=new Hls();
hls.loadSource(file);
hls.attachMedia(video);
hls.on(Hls.Events.MANIFEST_PARSED, function() {video.play();});
}
else if (video.canPlayType("application/vnd.apple.mpegurl"))
{
video.src=file;
video.addEventListener("loadedmetadata", function() {video.play();});
}
document.getElementById("filename").innerHTML=file;
}
</script>
</head>
<body>
<h1>Live Audio and Podcasts</h1>
<ul>
<?php
$arr=[];
$c=0;
if ($h=opendir("audio"))
{
while (($e=readdir($h))!==false)
{
if (strlen($e)>4)
if (substr_compare($e,".m4a",-4,4)===0)
$arr[$c++]="<li><a href=\"audio/".$e."\">".$e."</a> (<a href=\"#\" onclick=\"LoadAudio('".$e."')\">Load in Player</a>)</li>\n";
}
closedir($h);
}
if ($h=opendir("."))
{
while (($e=readdir($h))!==false)
{
if (strlen($e)>5)
if (substr_compare($e,".m3u8",-5,5)===0)
$arr[$c++]="<li><a href=\"".$e."\">".$e."</a> (<a href=\"#\" onclick=\"LoadM3U8('".$e."')\">Load in Player</a>)</li>\n";
}
closedir($h);
}
sort($arr);
foreach ($arr as $item)
echo $item;
?>
<li><a href="rss.php">RSS Feed</a></li>
</ul>
<p>
<span id="player" style="visibility: hidden;"></span>
<video id="video" controls autoplay style="width: 500px; height: 50px; visibility: hidden;"></video>
<br /><span id="filename"></span></p>
</body></html>