Ok.
I found out what was wrong. I corrected my php and js code and now it works perfect!
echo '<script>';
echo "\r\n";
echo 'var songs = [];';
echo "\r\n";
$spath = $_SERVER['DOCUMENT_ROOT'];
$spath .= "/vas/beta/audio-player/songs/";
$files = scandir($spath);
foreach($files as $file) {
if($file != '.' && $file != '..'){
echo 'songs.push("/vas/beta/audio-player/songs/', $file, '");';
echo "\r\n";
};
}
echo '</script>';
echo "\r\n";