Php 8.1 File append not working
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?
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.
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.