如何播放mp3音频存储im mysql的blob使用php [英] how to play mp3 audio stored im mysql blob using php
问题描述
我使用phpMyAdmin将存储在mysql数据库中的小型100KB mp3文件作为blob使用phpMyAdmin 然而,我无法在html上输出它并播放音频...这里是我的代码
require('mysqli_connect.php'); //包含数据库连接
$ sql =选择声音来自英文WHERE eWord LIKE'%。 $名称。 %或kWord LIKE'%。 $ name。%';
while($ row = mysql_fetch_array($ result)){
$ sound = $ row ['sound'];
echo'< audio controls>';
echo'< source src =data:audio / mp3; base64,'。$ row ['sound']。'>';
echo'< / audio>';
实际发生的情况是,在xampp localhost中加载页面
变灰html音频播放器来了,不玩任何东西
这里在我的phpMyAdmin
试图将音频源设置为数据uri,并在其中指定数据为base64编码,但使用二进制数据。
您必须将其转换为base64编码数据
echo'< source src =data:audio / mpeg; base64,'。base64_encode($ row ['sound'])。'> ;';
I have stored small 100kb mp3 files in mysql db as blob using phpMyAdmin
However i am unable to output it on html and play the audio...here is my code
require ('mysqli_connect.php'); //contains database connection
$sql="SELECT sound FROM english WHERE eWord LIKE '%" . $name . "%' OR kWord LIKE '%" . $name ."%'";
while($row=mysql_fetch_array($result)){
$sound=$row['sound'];
echo '<audio controls>';
echo '<source src="data:audio/mp3;base64,'.$row['sound'].'">';
echo '</audio>';
What actually happens is that on loading the page in xampp localhost grayed out html audio player comes and doesn't play anything
Here is how blob looks in my phpMyAdmin
You are trying to set your audio source as a data uri and in the it you specify the data is base64 encoded but use binary data.
You'll have to convert that to base64 encoded data
echo '<source src="data:audio/mpeg;base64,'.base64_encode($row['sound']).'">';
这篇关于如何播放mp3音频存储im mysql的blob使用php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!