PHP-MP3 icon indicating copy to clipboard operation
PHP-MP3 copied to clipboard

Php 8.1 File append not working

Open sodevrom opened this issue 3 years ago • 2 comments

Hello I am trying to append multiple mp3 files (same encoding), but the files do not get appended. Only the first file is saved in the final output. Example:

$file_mp3= \falahati\PHPMP3\MpegAudio::fromFile("audio1.mp3"); $file_mp3->append(\falahati\PHPMP3\MpegAudio::fromFile("audio2.mp3")); $file_mp3->saveFile("final_file.mp3");

No errors, only the first mp3 is added in the final file, and the final saved file size is equal to file 1.

Can you please help?

sodevrom avatar Nov 06 '22 22:11 sodevrom

Doing more tests, it seems the added function (to fix detection of end of file)

$this->memoryPointer = min($this->memoryLength, $index + $length); //this is the problem -> if ($this->memoryPointer >= $this->memoryLength) { return false; }

Is causing the problem with append. But if we remove this, in some cases it goes in an infinite loop.

sodevrom avatar Nov 07 '22 09:11 sodevrom

More testing, I think I Found a fix. Instead of if ($this->memoryPointer >= $this->memoryLength) { return false; }

We should write if($index+$length>$this->memoryLength) return false;

It works for me.

sodevrom avatar Nov 07 '22 09:11 sodevrom