Fijiannn Posted January 6, 2014 Share Posted January 6, 2014 So in my code below I have a script where it shuffles through .mp3 in a folder. How can I make the line below know which song the shuffle() has picked? $ThisFileInfo = $getID3->analyze($Songs[0]); <?php require_once('/home/manveers94/public_html/getID3-1.9.7/getid3/getid3.php'); $getID3 = new getID3; function fooFucker($url) { $a = join('/', array_map('urlencode', explode('/', $url))); return str_replace('+', '%20', $a); } $SongsFolder = "songs"; header("Content-Type: audio/x-mpegurl"); $body = ''; $Songs = glob($SongsFolder."/*.mp3"); shuffle($Songs); $first = 0; foreach($Songs as $Song) { $SongPath = pathinfo($Song); if ($first != 0) { $body .= "\n"; } $first = 1; $body .= "http://".$_SERVER['HTTP_HOST'].fooFucker(dirname($_SERVER['PHP_SELF']))."/".fooFucker($SongsFolder)."/".fooFucker($SongPath['basename']); } set_time_limit(30); $ThisFileInfo = $getID3->analyze($Songs[0]); getid3_lib::CopyTagsToComments($ThisFileInfo); $body .= 'File name: '.$ThisFileInfo['filenamepath'].'<br>'; $body .= 'Artist: '.(!empty($ThisFileInfo['comments_html']['artist']) ? implode('<BR>', $ThisFileInfo['comments_html']['artist']) : ' ').'<br>'; $body .= 'Title: '.(!empty($ThisFileInfo['comments_html']['title']) ? implode('<BR>', $ThisFileInfo['comments_html']['title']) : ' ').'<br>'; $body .= 'Bitrate: '.(!empty($ThisFileInfo['audio']['bitrate']) ? round($ThisFileInfo['audio']['bitrate'] / 1000).' kbps' : ' ').'<br>'; $body .= 'Play time: '.(!empty($ThisFileInfo['playtime_string']) ? $ThisFileInfo['playtime_string'] : ' ').'<br>'; header('Content-Length: ' . strlen($body)); echo $body; ?> Link to comment https://forums.phpfreaks.com/topic/285128-shuffle-mp3/ Share on other sites More sharing options...
requinix Posted January 6, 2014 Share Posted January 6, 2014 It "chose" $Songs[0]. That's the file. Link to comment https://forums.phpfreaks.com/topic/285128-shuffle-mp3/#findComment-1464029 Share on other sites More sharing options...
objnoob Posted January 6, 2014 Share Posted January 6, 2014 $songs = array('song a','song b','song c'); # the songs in order a, b, c shuffle($songs); # mix up the songs! PROBABLY not in order any more echo $songs[0]; # get the first song from the $songs array, which is PROBABLY not 'song a' since the songs were PROBABLY mixed up. ## PROBABLY IS A VERY IMPORTANT WORD HERE Link to comment https://forums.phpfreaks.com/topic/285128-shuffle-mp3/#findComment-1464033 Share on other sites More sharing options...
TinyI Posted January 6, 2014 Share Posted January 6, 2014 Hey, You need to put that line inside the foreach you have so it becomes $ThisFileInfo = $getID3->analyze($Song);and remember to put that into the foreach. After you shuffle and look at $songs[0], chances are that's not actually the first one anymore. The best way to test what's actually happening is do a print_r on $songs before you shuffle, then after and put an exit in. That way, you can see if 0 is working in the way of looking at the first one or if it goes off somewhere else. Link to comment https://forums.phpfreaks.com/topic/285128-shuffle-mp3/#findComment-1464036 Share on other sites More sharing options...
Fijiannn Posted January 6, 2014 Author Share Posted January 6, 2014 $songs = array('song a','song b','song c'); # the songs in order a, b, c shuffle($songs); # mix up the songs! PROBABLY not in order any more echo $songs[0]; # get the first song from the $songs array, which is PROBABLY not 'song a' since the songs were PROBABLY mixed up. ## PROBABLY IS A VERY IMPORTANT WORD HERE Why would I want to make an array of every song? I have over a 400+ songs in the folder with mp3 in it. Link to comment https://forums.phpfreaks.com/topic/285128-shuffle-mp3/#findComment-1464096 Share on other sites More sharing options...
Fijiannn Posted January 6, 2014 Author Share Posted January 6, 2014 It "chose" $Songs[0]. That's the file. That's not, the actual player is choosing a different song then the metadata is. Link to comment https://forums.phpfreaks.com/topic/285128-shuffle-mp3/#findComment-1464099 Share on other sites More sharing options...
objnoob Posted January 6, 2014 Share Posted January 6, 2014 Why would I want to make an array of every song? I have over a 400+ songs in the folder with mp3 in it. Well, if you don't want to make an array of every song.... you better delete $Songs = glob($SongsFolder."/*.mp3"); because that's exactly what it's doing Link to comment https://forums.phpfreaks.com/topic/285128-shuffle-mp3/#findComment-1464185 Share on other sites More sharing options...
Fijiannn Posted January 7, 2014 Author Share Posted January 7, 2014 Well, if you don't want to make an array of every song.... you better delete $Songs = glob($SongsFolder."/*.mp3"); because that's exactly what it's doing Okay well, how can I do it using that? Link to comment https://forums.phpfreaks.com/topic/285128-shuffle-mp3/#findComment-1464201 Share on other sites More sharing options...
GetFreaky Posted January 7, 2014 Share Posted January 7, 2014 Okay well, how can I do it using that? You need an array to store all of your songs and shuffle them using the shuffle((array) $array) function, You are not making an array of every song, you are storing every song in 1 array. Link to comment https://forums.phpfreaks.com/topic/285128-shuffle-mp3/#findComment-1464210 Share on other sites More sharing options...
objnoob Posted January 8, 2014 Share Posted January 8, 2014 You need an array to store all of your songs and shuffle them using the shuffle((array) $array) function, You are not making an array of every song, you are storing every song in 1 array. Right! We're not making an array for every song, we're making an array of every song (that matched the glob pattern). Link to comment https://forums.phpfreaks.com/topic/285128-shuffle-mp3/#findComment-1464376 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.