Php – How to add HTML 5 audio player

audiobase64htmlphp

I'm getting source file from a folder. When I select a ready-made mp3 file like song as src in audio tag, It works. But when I select a mp3 file(call recording file) created from base64 encoded string, I doesn't work. File is perfectly created as I checked in folder and played. Problem is that when I move curser on player, it becomes transparent just like an image. If anyone know answer then please explain with an example. Thank You. Here is my code.

<?php

$data = $_REQUEST['data'];
$filename = $_REQUEST['filename'] . ".3gpp";
$imei = $_REQUEST['imei'];

$dir = __DIR__ . "/recordings/";
$file = file_put_contents($dir . $filename, base64_decode($data));
$rloc = "recordings/" . $filename;

$str = "INSERT INTO recording(data, filename, imei) VALUES('$rloc', '$filename', '$imei')";
$qry = mysql_query($str);

?>
<html>
<audio controls autoplay="">
       <source src="<?php echo $row['data']; ?>">
</audio>
</html>

Best Solution

You need to prefix the data:audio/mp3;base64, to the Data URI. Use this instead:

<audio controls autoplay="">
    <source src="data:audio/mp3;base64,<?php echo $row['data']; ?>">
</audio>