I just built a mp3 player from playlist.me the script looks like this:
<!-- Song Player http://playlist.me -->
<script
type="text/javascript"
src="http://playlist.me/w/script.js"
data-config="{'skin':'skins/black/skin.css','volume':50,'autoplay':false,'shuffle':false,'repeat':1,'placement':'bottom','showplaylist':false,'playlist':[{'title':'Song TItle','url':'http://sourcemp3.com/music.mp3'}]}" >
</script>
<noscript>
<a href="http://playlist.me/w/i.php">SCM music player</a>
</noscript>
<!-- playlist.me script end -->
The problem is that I have to manually edit the script to add more MP3 files, how do I add files without manually edit the script? My MP3 files are located in /mnt/usb
. I can do find
with bash to list all the music files but how do I put them in the script above? My goal is that I want to be able to update my MP3 files by just copying and pasting my files to /mnt/usb/
and they'll show in my web player automatically.
UPDATE as suggested, I edited my script to be like this:
<?php
$glob = glob('/mnt/usb/*.mp3');
$url = '/mnt/usb/';
$playlist = array();
foreach ($glob as $mp3) {
$playlist[] = array('title' => $mp3, 'url' => $url . $mp3);
}
echo '
<html>
<head>
<title> MP3 Player</title>
</head>
<body>
<script
type="text/javascript"
src="http://playlist.me/w/script.js"
data-config="{\'skin\':\'skins/black/skin.css\',\'volume\':50,\'autoplay\':false,\'shuffle\':false,\'repeat\':1,\'placement\':\'bottom\',\'showplaylist\':false,\'playlist\':[{\'title\':\'Song TItle\',\'url\':\'http://sourcemp3.com/music.mp3\'}]}" >
</script>
<noscript>
<a href="http://playlist.me/w/i.php">SCM music player</a>
</noscript>
</body>
</html>';
echo sprintf("'playlist':%s", json_encode($playlist));
?>
But I get the following error: Fatal error: Call to undefined function json_encode() in /www/music.php on line 25
and the music won't load either. Please help
UPDATE AGAIN I got that json part sorted out, now the problem is like this:
My script:
<?php
$glob = glob('/mnt/usb/*.mp3');
$url = '/mnt/usb/';
$playlist = array();
foreach ($glob as $mp3) {
$playlist[] = array('title' => $mp3, 'url' => $url . $mp3);
}
echo sprintf("'playlist':%s", json_encode($playlist));
echo '
<html>
<head>
<script
type="text/javascript"
src="http://playlist.me/w/script.js"
data-config="{"skin":"skins/black/skin.css","volume":50,"autoplay":false,"shuffle":false,"repeat":1,"placement":"bottom","showplaylist":false,"playlist":" >
</script>
<title> MP3 Player</title>
</head>
<body>
<noscript>
<a href="http://playlist.me/w/i.php">SCM music player</a>
</noscript>
</body>
</html>';
echo sprintf("'playlist':%s", json_encode($playlist));
?>
How do I solve this?