Embedding Audio Clips with Drupal or PHP

Fri, 27 Apr 2012

Google player works nicely to display audio clips in some browsers but doesn’t work on the iPad as it is driven by Flash. Alternatively you can display an audio clip in HTML 5 using the built in ‘audio controls’ but that won’t work in some of the older browser. The same problem occurs with flash animations.

In an attempt to solve this tricky dilemma I’ve written a quick Drupal module to display an audio clip player and animations in a variety of browsers. You can see the the result below. Let me know if you can see them okay!

displayaudioclip($audio)


displayanimation($clip)


If you are a Drupal user you can download the files here.

Install the module into your modules directory and activate it.

Displaying Audio Files

The audio files must be in mp3 format.

Create a folder called ‘audio’ in your root directory. (You can change this if you want by editing the $path= line in the sniffer.module file) Upload your audio clip in mp3 format into the audio folder.

Create a new blog entry. Set the input format to PHP code. Write your blog entry as usual.

In the place where you want the audio clip to appear add the following code.

<?php displayaudioclip(‘audio.mp3’) ?>

Displaying Animations

Create your animation in Flash and save it as a .swf file. You need to save it as SWF 8 and ActionScript 2.0 as later versions don’t convert so well.

Upload the file to the Google Swiffy website. This tool will convert the animation to HTML format for you. You can save the converted file at the bottom of the page.”

You should now have two animation files. animation.swf and animation.html Upload them both to folder ‘swiffy’ in your site’s root. You can rename this folder by editing the ‘$path=’ line in the .module file if you prefer.

Create a new blog entry. Set the input format to PHP code. Write your blog entry as usual.

In the place where you want the animation clip to appear add the following code.

<?php displayanimation(‘animation’) ?>

Notice that there is no .swf or .html after the file name.
When you view the page you should see the animation displayed either as a Flash file or as an HTML file depending on which browser you use to view it.

If you don’t use Drupal you will probably still find the sniffer module. Download the file. Open the file sniffer.module in your favourite text editor and you’ll find a couple of PHP functions. displayaudioclip($audio) and displayanimation($clip) which you can use on your site with a little bit of PHP knowledge.

  To receive new blog posts by email

Comments (5)

  • michael42er April 27, 2012 at 10:46 am

    The audio clip is perfect

    The audio clip is perfect with flash and Firefox 12.0

    Michael

    • umehta April 27, 2012 at 12:12 pm

      It works fine with Firefox

      It works fine with Firefox 11.0 too

      • maxlrainer April 27, 2012 at 3:05 pm

        ok with Firefox 12, Flash

        ok with Firefox 12, Flash Player 11.2.202.233 and Windows Vista SP 2

  • JayHavvic April 27, 2012 at 3:45 pm

    Rob,
    Works great with Chrome

    Rob,

    Works great with Chrome 18.xxxx

    Thanks,

    J

  • robives April 27, 2012 at 5:23 pm

    Thanks everyone. Works on an

    Thanks everyone. Works on an iPad as well. Thanks #1 Dad!

Comments are closed.