Ich bin mal nach diesen beiden Anleitungen vorgegangen:
http://www.phpgangsta.de/moglichkeiten-…mp3s-auszulesen
http://stackoverflow.com/questions/1674…-an-mp3-id3-tag
Damit funktioniert es einwandfrei, einschl. Auslesen des Bildes, wenn denn eines vorhanden ist:
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
/* ####################################################################################
Ein einfacher Audio-Player auf HTML5 Basis.
Browser: IE 9+, Chrome (auch iOS), Safari (auch iOS), Firefox ab V. 21, neue Opera
http://webdesign.weisshart.de 2014
Lizenz: CC BY-NC-SA 3.0 DE
##################################################################################### */
/* ################### hier die .mp3 Dateien (Streams gehen als https nicht) ######## */
$url = [];
/* ################### und hier die angezeigten Titel ######################### */
$name = [];
$image = [];
// include getID3() library (can be in a different directory if full path is specified)
require_once 'getID3-1.9.12/getid3/getid3.php';
// Initialize getID3 engine
$getID3 = new getID3;
$files = glob("audio/*.mp3");
foreach ($files as $filename) {
$url[] = $filename;
$ThisFileInfo = $getID3->analyze($filename);
// Analyze file and store returned data in $ThisFileInfo
$name[] = $ThisFileInfo['tags']['id3v2']['title'][0];
if(isset($ThisFileInfo['comments']['picture'][0])){
$image[] = 'data:'.$ThisFileInfo['comments']['picture'][0]['image_mime'].';charset=utf-8;base64,'.base64_encode($ThisFileInfo['comments']['picture'][0]['data']);
} else {
$image[] = '';
}
}
/* ##################### ab hier nicht mehr editieren ########################## */
$aufruf ="";
$direktlink ="";
function isIOS($user_agent=NULL) {
if(!isset($user_agent)) {
$user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
}
return (strpos($user_agent, 'iPhone') !== FALSE || strpos($user_agent, 'iPad') !== FALSE || strpos($user_agent, 'iPod') !== FALSE );
}
/* den uebergebenen Titel abfragen */
if (isset($_REQUEST['titel'])) {
$autoplay="autoplay"; /* kein Autoplay in iOS */
$neuer_titel=true;
for ($i = 1; $i <= count($url); $i++) {
if ($_REQUEST["titel"] == $i) {$titel = $url[$i-1];}
}
} else {
$titel = $url[0];
$autoplay = "";
}
/* die Linkliste generieren */
for ($i = 1; $i <= count($url); $i++) {
$aufruf .= '<li><a href="?titel='.$i.'"> '.$name[$i-1];
if ($titel == $url[$i-1]) {
$aufruf .= "<span class='star'> ✔︎</span>";
}
if ($image[$i - 1] != '') $aufruf .= '<img id="FileImage" width="150" src="' . $image[$i - 1] . '" height="150">';
$aufruf .= "</a></li>\n";
$direktlink .= '<li><a style="color:#000" href="'.$url[$i-1].'"> '.$name[$i-1].'</a>';
$direktlink .= '</li>';
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
<link rel="stylesheet" type="text/css" media="screen" href="audiotest.css" />
<title>HTML5 Audio und Radio Player</title>
<!-- <script src="modernizr.custom.29132.js"></script> -->
<?php
if(isIOS()) {
echo '
<style>
#player {background: #e1e1e1;border: 2px solid #aaa;}
li a {color:#000 !important;}
li {border-top: 1px solid #aaa}
audio {margin: 10px 0 5px 0}
</style>
';
}
?>
</head>
<body onload="Lautstaerke()">
<!-- <h2>HTML5 Audio- und Radio-Player</h2> -->
<div id="h2"></div>
<script>
if (top.location == self.location) {
// Seite in einem Frame geladen
document.getElementById('h2').innerHTML='<h1>HTML5 Audio- und Radio-Player</h1>';
}
</script>
<div id="ie_fallback"></div>
<div id="player">
<!-- erstaunlich: ohne <source> tag gehts auch mit VO auf iOS -->
<audio id="innerplayer" src="<?php echo $titel; ?>" controls <?php echo $autoplay; ?>></audio>
<ul>
<?php echo $aufruf; ?>
</ul>
</div>
<div id="down_hinweis"></div>
<!-- <p id="gemafrei" class="bem">Gemafreie Demo-mp3: <a href="http://www.MP3-GEMA-frei.de">MP3-GEMA-frei.de</a></p> -->
<?php
$neuer_titel = 0;
if (isset($_REQUEST['titel'])) {$neuer_titel=1;}
?>
<script>
// if (!Modernizr.audio.mp3) {
// document.getElementById('player').style.display = 'none';
// document.getElementById('ie_fallback').innerHTML='<p>Ihr Browser kann leider keine Audios im MP3-Format abspielen. Das tut uns leid. <br />Ersatzweise hier die Links zum Abspielen in einem installierten Player oder zum Download (rechte Maustaste).</p> <ul><?php echo $direktlink; ?></ul>';
// }
/* Damit Screen Reader Ausgaben nicht uebertoent werden: */
function Lautstaerke() {
document.getElementById("innerplayer").volume=0.7;
/* Fokus auf Player setzen nach Anwahl */
var neu = <?php echo $neuer_titel; ?>;
if ( neu === 1 ) {
document.getElementById('innerplayer').focus();
}
}
</script>
</body> </html>
Alles anzeigen
Dieses Skript liest die MP3s aus dem Unterverzeichnis audio aus.