Uploading an audio recording to mysql and playing in website

后端 未结 8 1516
生来不讨喜
生来不讨喜 2020-12-03 09:44

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

相关标签:
8条回答
  • 2020-12-03 10:13

    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;
    
    0 讨论(0)
  • 2020-12-03 10:14

    If HTML5 is not an option, for inline playback, the best option supported out of the box by the majority of current browsers will be flash based. Flash still requires a plugin, but it's much more widely installed than Quicktime AFAIK.

    The Google mp3 player that Tomasz suggested is a good choice. There are many more out there though. See for example http://www.webdesignbooth.com/10-easy-to-implement-flash-based-mp3-players-for-your-website/

    0 讨论(0)
提交回复
热议问题