I'm trying to create a jPlayer playlist based on mp3 files from a folder. And I found jPlaylister: http://jplaylister.yaheard.us/v_0.65/
I've found a similar question here: Dynamically populate playlist with JSON from PHP in jPlayer
Now, I'm not the expert on these things. I'm more of a design and simple code kind of guy. But I've tried to build the code to my likings, and I've come up with this. Which doesn't work at all. I'm not sure how to debug it either, because I can't get a response from $.getJSON
Here's my code right now:
$(document).ready(function(){
var cssSelector = {
jPlayer: "#jquery_jplayer_1",
cssSelectorAncestor: "#jp_container_1"
};
var playlist = []; // Empty playlist
var options = {
swfPath: "js",
supplied: "mp3"
};
//var playlist = [{"title":"Kalimba","mp3":"/path/to/mydirectory/Kalimba.mp3"},{"title":"Maid with the Flaxen Hair","mp3":"/path/to/mydirectory/Maid with the Flaxen Hair.mp3"},{"title":"Sleep Away","mp3":"/path/to/mydirectory/Sleep Away.mp3"}];
var url= "getSongurl.php";
var song = "Assets/mp3/mysong";
var myPlaylist = new jPlayerPlaylist(cssSelector, playlist, options);
$.getJSON(url, {songurl: song}, function(data) {
$.each(data, function(key, val) {
myPlaylist.add(value);
})
});
});
I want to pass the song variable to JSON so I can process the folder in PHP and return all files from that folder.
Now, here's the PHP file:
<?php
$results = array();
$directory = $_POST['songurl'];
$handler = opendir($directory);
while ($file = readdir($handler)) {
$results[] = $file;
<script type="text/javascript">
alert("file: <?php echo $file; ?>");
</script>
}
$limit = count($results();
$i = 0;
while ($i < $limit) {
$filesJson = array(
'title:' => $i,
'mp3:' => $i
);
}
//tidy up
closedir($handler);
echo json_encode($filesJson);
?>
I tried to put an alert in there, but I don't get any alerts either. Probably just me who've done something really wrong here..