Forum Moderators: coopster
Array
(
[0] => audio/1.mp3
[1] => audio/2.mp3
[2] => audio/3.mp3
[3] => audio/4.mp3
[4] => audio/5.mp3
)
$mp3datafile = 'audio/1.mp3';
$m = new mp3file($mp3datafile);
$mp3dataArray = $m->get_metadata();
print_r($mp3dataArray);
unset($mp3dataArray); Array
(
[Filesize] => 31972
[Encoding] => CBR
[etc]
) foreach ($imagearray as $key => $val) {
$tnsoundfile = $xml_generator->addChild('item');
$tnsoundfile->addChild('title', $podcasttitle);
$enclosure = $tnsoundfile->addChild('enclosure');
$enclosure->addAttribute('url', $val); // that's the filename
$enclosure->addAttribute('length', $mp3dataArray[Filesize]); // << Length is file length, not time. But later I also need $mp3dataArray[Length mm:ss] for duration tag.
$enclosure->addAttribute('type', 'audio/mpeg');
$tnsoundfile->addChild('guid', $path_to_image_dir.'/'.$val);
} foreach ($mp3data as $key => $val) {
$mp3datafile = $val;
$m = new mp3file($mp3datafile);
$mp3dataArray = $m->get_metadata();
print_r($mp3dataArray);
unset($mp3dataArray);
}
foreach ($mp3data as $key => $val) {
$mp3datafile = $val;
$m = new mp3file($mp3datafile);
$mp3dataArray = $m->get_metadata();
$mp3testarray = array($mp3dataArray);
}
print_r($mp3dataArray); foreach ($mp3data as $key => $val) {
$mp3datafile = $val;
$m = new mp3file($mp3datafile);
$mp3dataArray = $m->get_metadata();
$mp3testarray = array($mp3dataArray);
}
print_r($mp3dataArray); $allresults = array();
foreach ($mp3data as $key => $val) {
$mp3datafile = $val;
$m = new mp3file($mp3datafile);
$mp3dataArray = $m->get_metadata();
$allresults[] = $mp3dataArray;
}
print_r($allresults);
<?php
//This creates an array variable (empty):
$allresults = array();
//This starts a loop, running through each item inside array mp3data; each loop executes the code inside the braces:
foreach ($mp3data as $key => $val)
{
//This takes the value of the array item (the file path/name) and set it as the "mp3 file":
$mp3datafile = $val;
//This creates an instance of 'mp3file' using the mp3 file:
$m = new mp3file($mp3datafile);
//This creates an array of MP3 data using the mp3file object for the current mp3 file:
$mp3dataArray = $m->get_metadata();
//This "adds" the current mp3 data array onto the end of the array "allresults":
$allresults[] = $mp3dataArray;
}
//This prints out (to screen) in a human-friendly-readable form, all of the contents within variable (array) allresults:
print_r($allresults);
?> Array
(
[0] => Array
(
[title] => some title
[bitrate] => 128
[length] => 12:38
)
[1] => Array
(
[title] => some title
[bitrate] => 128
[length] => 12:38
)
[2] => Array
(
[title] => some title
[bitrate] => 128
[length] => 12:38
)
[3] => Array
(
[title] => some title
[bitrate] => 128
[length] => 12:38
)
[4] => Array
(
[title] => some title
[bitrate] => 128
[length] => 12:38
)
) <?php
//assumes 'allresults' or such is already defined/valued
foreach ($allresults as $mp3data)
{
$title = $mp3data['title'];
$bitrate = $mp3data['bitrate'];
$length = $mp3data['length'];
echo "<div>MP3 Song - Title($title) BitRate($bitrate) Length($length)</div>";
}
?> <?php echo '<pre>';print_r($someArray);echo '</pre>';