I use javascript with function createAnalyser()
to create visualization for mp3 tracks, but the process of getting buffers too long.
Therefore, I intend to write buffers into the database, when play the song then the extraction buffers more quickly, that is my thought.
In my code, I use XMLHttpRequest()
to receive the arraybuffer
from mp3 files, but I don't know how to put arraybuffer
into the database.
var request = new XMLHttpRequest();
request.open('GET', 'music.mp3', true);
request.responseType = 'arraybuffer';
request.onload = function() {
context.decodeAudioData(request.response, function(buffer) {
$.post('insert.php', {
data: buffer
}, function(res) {
alert(res);
});
});
}
request.send();
And here is my PHP code:
<?php
$data = @$_POST['data'];
if (!$data) echo 'No data';
else {
$open = fopen('audio.txt', 'a+');
fwrite($open, $data);
fclose($open);
echo 'Done!';
}
?>
Please help me!