Does anyone know of a way to limit the amount of seconds an audio file plays either using a php function or a certain audio player? For example, I would like to play only the first 25 seconds of all the audio files on my website. thanks for any suggestions.
Way that first comes to my mind would be to re-record or shorten the original audo file to just the first 25 seconds of it, then put an if statement in php to say whether to show the link to play the full file or shortened file depended on something 'eg: they are registered or not'
I need something that would do this automatically...as users will be uploading the files and it will take too long to make shorter versions of all the files...especially if the site gets big
Hmm, I think this could be done using restrictions or some sort of script, give me 5 minutes and Ill see what I can find out.
I came up with this. <?php $local_file = '/path/to/file.mp3'; // Set this to the file that you are trying to play. $bitrate = 128; // Bitrate of .mp3 (128, 256, 320, etc). $length = 29; // Length in seconds to play. if(file_exists($local_file) && is_file($local_file)) { $file_size = (32 / 8) + (($bitrate / 8) * $length); // .mp3 has a 32bit header, and divide by 8 to get bits to bytes. header('Content-Type: audio/mpeg'); header('Content-Length: ' . $file_size); $file = fopen($local_file, "rb"); echo fread($file, $file_size); fclose($file); } ?> PHP: It's untested! Let me know if it works.