Audio recording in Django apps with flvar
In a site I'm working on there must be a feature that would allow recording audio and listening to refference recordings. I had to add a flash recorder and player for audio. For recording I've got flvar (non-free), and for playing flowplayer. Using flowplayer isn't a problem - just give him the url to the file. Recording is more complicated as it works with a media server. I used Red5 under Linux.
Installing Red5 under LinuxCheck if Red5 is in your distribution repository. If not we have to compile it. To do this install jdk and ant. After that download Red5 package or SVN code:
Configuring Red5 for Flvar
The media server has a folder called webapps. It contains all media apps with their configs. In the flvar package you will get preconfigured apps. Just copy contents of Files to upload to your media server (Red5) to webapps and that's it. The audiorecorder app will be used by the flash applet. All flv files will be stored also in it.
Using flvar with Django
If you got a binary applet only then you have to do a bit of url mapping, as the widget seems to have hardcoded filenames for config/save and language files. For example for config file it will try to call "./avc_settings.php" url. But we don't need that PHP to make it work.So here is a very basic app for recoding audio files. Copy contents of Files to upload to your website to site_media/recorder of you Django project. Now create an application for recording. I called it recorder, and I've mapped some URLs that are required for it to work:
/recorder/ view will show a HTML template with the flash recorder. Under /recorder/translations/en.xml I've mapped it default language file, and /recorder/avc_settings.php is pretending to be the config file. Saving a recording will call a view mapped under /recorder/save_audio_to_db.php.Now copy translations/en.xml to templates folder under recorder/en.xml. Create also recorder/flash_recorder.html template:
Where userId is the ID of user using the recorder (login required in my case), and recorderId I use for the object ID to which the recording is associated with (static in this example).Now the view that will return the configuration. It's a key=value string joined with & character: When recording is saved you will get all data via POST request (user id, recorderId, filename etc.): And thats it. Now go to /recorder/ to use the widget: