I’m trying to display the duration of an audio file without playing it.
Is that possible with a simple thing?
<?php dump($file) ?>
doesn’t seem to get that info. Is there another way?
thanks.
I don’t think there is a function out of the box with Kirby but you can use a library like getID3
or ffprobe
.
Below is an example using GetID3:
// Path to your audio file
$audioFilePath = 'path/to/audio.mp3';
// Initialize getID3
$getID3 = new getID3;
// Analyze the audio file
$audioFileInfo = $getID3->analyze($audioFilePath);
// Get the duration
$durationInSeconds = $audioFileInfo['playtime_seconds'];
echo "Audio duration: {$durationInSeconds} seconds\n";
But you will need to check your hosing if either libs are available