上传录音到MySQL并在网站上玩 [英] Uploading an audio recording to mysql and playing in website

查看:117
本文介绍了上传录音到MySQL并在网站上玩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个上传的手机应用程序,上传图像或录音。图像可以上传到一个MySQL数据库,并在网页中显示没有问题,我有正在播放网页上的音频问题,我已经被播放MP3文件,我已经放在数据库中自己虽然网页测试的网页。当我上传MP3文件从手机或仿真器没有发挥。数据库填充了一个文件的大小,并在网页上的媒体播放器并不加载,但没有发挥

编辑1 由于写这个我已经学会了为.amr文件Android的记录,而不是.MP3,我已创建文件。从那时起,我可以使用QuickTime或Real Player播放我的桌面上播放的文件。当我尝试通过Web浏览器来播放该文件,我收到了QuickTime的标志,中间一个问号。下面是我的$ C $下播放该文件。

 标题(内容类型:音频/ AMR');

$查询=请求mysql_query(SELECT * FROM媒体WHERE media_id ='$ IDD');

$行= mysql_fetch_array($查询);

回声$行['文件'];
 

嵌入code,其中110为$ IDD在上面

 <对象数据=?sound.php ID = 110宽度='391'高度='298'> <嵌入SRC ='sound.phpWIDTH =391高度='298'>< /嵌入>'错误'< /对象>
 

编辑2

如果我把同样的文件直接在我的服务器上,而不是在数据库中该code下载文件

 <对象的classid =CLSID:02BF25D5-8C17-4B23-BC80-D3488ABDDC6BWIDTH =100HEIGHT =100codeBase类='的http:// www.apple.com/qtactivex/qtplugin.cab'>
<参数名称='src'中值=apr.amr>
< PARAM NAME =自动播放价值=真>
< PARAM NAME =控制器值=真>
<参数名称='循环'值=真>
< EMBED SRC =apr.amrWIDTH =100HEIGHT =100自动播放=真正的控制器=真正的循环=真正的PLUGINSPAGE =HTTP://www.apple.com/quicktime/下载/'>
< /嵌入>
< /对象>
 

编辑3上传code

 如果(使用isset($ _ FILES ['形象'])及和放大器; $ _FILES ['形象'] ['大小'] 0){

      $大小= $ _FILES ['形象'] ['大小'];
      $型= $ _FILES ['形象'] ['类型'];

      存储在服务器上//临时文件名
      $ tmpName = $ _FILES ['形象'] ['tmp_name的值'];

      //读取文件
      $计划生育=的fopen($ tmpName,'R');
      $数据= FREAD($计划生育,档案大小($ tmpName));
      fclose函数($ FP);

      $数据=和addslashes($的数据);

      //创建查询,插入
      //进入我们的数据库。
      $查询=插入媒体;
      $查询=(文件,FILE_SIZE,FILE_TYPE)VALUES('$的数据,$大小','$类型')。
      $结果=请求mysql_query($查询,$链接);

      $ mediaid = mysql_insert_id();

    $性别= $ _ POST ['性别'];
    $ cat_id = $ _ POST ['猫'];
    $名称= $ _ POST ['名称'];
    $经纬度= $ _ POST ['纬度'];
    $ LON = $ _ POST ['LON'];
    $ USER = $ _ POST ['用户'];


  $查询=INSERT INTO实例(姓名,性别,cat_id,经度,纬度,USER_ID)VALUES('$名','$性别,$ cat_id','$结肠','$纬度,$用户');
  $结果= mysql_query($查询);


      $实例id = mysql_insert_id();

      $ query4 =INSERT INTO media_link;
      。$ query4 =(media_id,INSTANCE_ID)VALUES('$ mediaid','$实例id');
      $ results4 =请求mysql_query($ query4,$链接);

    }

//关闭我们的MySQL链接
则mysql_close($链接);
?>
 

解决方案

所以,如果你有一个AMR文件(我没有测试过这一点,所以你必须要尝试了这一点),你将需​​要提取AMR音频并将其转换为MP3。不幸的是这似乎是相当罕见的在Java中,但(相当痛苦的)谷歌搜索打开了这个链接: http://www.benmccann.com/blog/extracting-amr-audio-from-android-3gp-files/ 声称证明提取一个音频3GPP视频文件,所以他们至少有一个AMR解析器。我想看看他们使用的基础库,isobox4j(在的http://groups.google.com/group/android-developers/browse_thread/thread/245c9de4132c2ab0?fwc=1)

:如果你既可以看到
  1. 提取手机中的应用程序中的音频,转换成MP3,然后上传MP3(可能是最简单的选择,坦率地说:保持服务器的简单)
  2. 提取服务器上的音频并转换为MP3的MP3流媒体的网页(可能更难,坦率地说)之前。

祝你好运。

编辑:或者你可以希望在客户端有一个合适的浏览器插件:破碎的QuickTime的标志表示QuickTime的不具有codeC吧

编辑2:你可能需要设置的内容类型的插件,所以它知道该怎么做。对于AMR尝试添加

 标题(内容类型:音频/ AMR);
 

在你的PHP echo语句之前,如果这还不够一个MIME类型添加到您的嵌入是这样的:

 <对象数据=?sound.php ID = 110宽度='391'高度='298'> <嵌入SRC ='sound.php类型=音频/ AMRWIDTH =391高度='298'>< /嵌入>'错误'< /对象>
 

其是否正常工作。

编辑:试试这个。不知道,如果$行['文件']被认为是一个字符串或数组,但微调可能会做你的需要。

 < PHP

标题(内容类型:音频/ AMR');

$查询=请求mysql_query(SELECT * FROM媒体WHERE media_id ='$ IDD');

$行= mysql_fetch_array($查询);

回声修剪($行['文件']);
出口;
 

I have an upload phone app that uploads either images or audio recordings. The image can be uploaded to a mysql database and displayed no problem in a webpage, The problem i am having is playing the audio on the webpage, i have tested the webpage by playing mp3 files i have placed in the database myself though the webpage. When i upload an mp3 file from the phone or emulator nothing plays. The database is populated with a file size and on the webpage a media player does load, but nothing plays

Edit 1 Since writing this i have learnt that android records in .amr files and not .mp3 which i had been creating the file as. Since then i can play the file on my desktop using either quicktime or real player. When i attempt to play the file through a web browser i get a quicktime logo with a question mark in the middle. Below is my code for playing the file.

header('Content-type: audio/amr');

$query = mysql_query("SELECT * FROM media WHERE media_id= '$idd'"); 

$row = mysql_fetch_array($query); 

echo $row['file'];

Embed code where 110 is $idd in the above

<object data="sound.php?id=110 width='391' height='298'"> <embed src='sound.php' width='391' height='298'></embed>'ERROR' </object>

Edit 2

If i put the same file directly on my server and NOT in the database this code downloads the file

<OBJECT classid='clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B' width="100" height="100"codebase='http://www.apple.com/qtactivex/qtplugin.cab'>
<param name='src' value="apr.amr">
<param name='autoplay' value="true">
<param name='controller' value="true">
<param name='loop' value="true">
<EMBED src="apr.amr" width="100" height="100" autoplay="true" controller="true" loop="true" pluginspage='http://www.apple.com/quicktime/download/'>
</EMBED>
</OBJECT>

Edit 3 upload code

if (isset($_FILES['image']) && $_FILES['image']['size'] > 0) { 

      $size = $_FILES['image']['size'];
      $type = $_FILES['image']['type'];

      // Temporary file name stored on the server
      $tmpName  = $_FILES['image']['tmp_name'];  

      // Read the file 
      $fp      = fopen($tmpName, 'r');
      $data = fread($fp, filesize($tmpName));
      fclose($fp);

      $data = addslashes($data);

      // Create the query and insert
      // into our database.
      $query = "INSERT INTO media";
      $query .= "(file, file_size, file_type) VALUES ('$data','$size','$type')";
      $results = mysql_query($query, $link);

      $mediaid = mysql_insert_id();

    $gender = $_POST['gender'];
    $cat_id = $_POST['cat'];
    $name = $_POST['name'];
    $lat = $_POST['lat'];
    $lon = $_POST['lon'];
    $user = $_POST['user'];


  $query="INSERT INTO instance (name, gender, cat_id, lon, lat, user_id) VALUES ('$name', '$gender', '$cat_id', '$lon', '$lat', '$user')";
  $result=mysql_query($query);


      $instanceid = mysql_insert_id();

      $query4 = "INSERT INTO media_link";
      $query4 .="(media_id, instance_id) Values ('$mediaid','$instanceid')";
      $results4 = mysql_query($query4, $link);

    }

// Close our MySQL Link
mysql_close($link);
?>

解决方案

So if you have an AMR file (I haven't tested this, so you'll have to try this out) you will need to extract the AMR audio and convert it to MP3. Unfortunately it appears to be rather rare in Java, but a (rather painful) Google search turned up this link: http://www.benmccann.com/blog/extracting-amr-audio-from-android-3gp-files/ which claims to demonstrate extracting the audio from a 3gpp video file, so they at least have an AMR parser. I would look at the underlying library they use, isobox4j (discussed at http://groups.google.com/group/android-developers/browse_thread/thread/245c9de4132c2ab0?fwc=1) and see if you can either:

  1. Extract the audio in the phone app, convert to mp3 and then upload the mp3 (probably the easiest option, frankly: keeps the server simple).
  2. Extract the audio on the server and convert to mp3 before streaming the mp3 to the web page (probably harder, frankly).

Good luck.

EDIT: or you could hope the client has an appropriate browser plugin: the broken quicktime mark indicates quicktime doesn't have a codec for it.

EDIT 2: You probably need to set a content-type for the plugin so it knows what to do. For AMR try adding

header("Content-type: audio/amr");

before the echo statement in your PHP and if that isn't enough add a mime type to your embed like this:

<object data="sound.php?id=110 width='391' height='298'"> <embed src='sound.php' type="audio/amr" width='391' height='298'></embed>'ERROR' </object>

See if that works.

EDIT: try this. Not sure if the $row['file'] is considered a string or an array, but the trim might do what you need.

<?php

header('Content-type: audio/amr');

$query = mysql_query("SELECT * FROM media WHERE media_id= '$idd'"); 

$row = mysql_fetch_array($query); 

echo trim($row['file']);
exit;

这篇关于上传录音到MySQL并在网站上玩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆