Soukie's Place

keeping track of random thoughts

Degradable HTML5 audio and video Plugin

Screenshots of the plugin

Screenshots of HTML5 video and audio in action

Wordpress plugin for html 5 audio and video allows you to embed media for native playback in supported browsers and offers a graceful degradation for unsupported browsers. Feel free to download the plugin, and use the Comments section to leave feedback or feature requests.

Download the plugin and follow the installation instructions, or use the feature Add New under Plugins in your WordPress installation to search for this plugin for an automated installation.

You can take a look at the plugin in action with audio and video playback. Try them out with different browsers.

Description and Features

Embed video and audio on your website using shortcodes. The plugin enables html5 native playback for users with compatible browsers while offering an elegant degradation to other users through very lightweight Flash players. For html5 playback, it auto-detects and offers different alternatives, or degrades to Flash, and (failing even that) to download links.

Typical usage is simply [audio src="http://myblog.com/wp-content/uploads/2009/09/mysong"]

The plugin will make sure this does the following:

  1. If the user has an HTML5 support for video and audio, it will play the media natively in an appropriate format.
  2. Otherwise, if the user has Flash, it will play the media in lightweight Flash players.
  3. Otherwise, there will be a link for the audio or video files so that the user can still play them using their installed software players.

The plugin also allows you to ignore “ogg” versions and force Firefox to fallback on Flash.

Codecs and browsers: The current situation with HTML5 is not ideal. For video, you have to supply two formats to support all browsers. But if you do not mind forcing Firefox to fall back to Flash, you can provide H.264 version only. See the tables below showing the formats supported in the current browsers.

VIDEO           H.264   Ogg Theora
                .m4v      .ogg
Firefox 3.5      -         X
Safari 4.0       X         -
Chrome 3.0       X         X
Other (Flash)    X         -`

When a browser supports multiple formats and the files are available, the preference goes from left to right (e.g. Chrome will prefer the H.264 format; reflecting the quality of the codecs).

AUDIO         WAVE   MPEG-4   Ogg Vorbis   MPEG
              .wav    .m4a       .ogg      .mp3
Firefox 3.5     X       -          X         -
Safari 4.0      X       X          -         X
Chrome 3.0      -       X          X         -
Other (Flash)   -       -          -         X`

For audio, you have to include at least .mp3 and .ogg versions to cover all browsers. (Or, you can supply .mp3 and .m4a only which will force Firefox to play mp3 in Flash). Other formats are optional. Again, the preference for multiple available files in browsers supporting multiple codecs is left to right.

The Flash players used are a standalone version of WordPress Audio Player by Martin Laine, and Videoplayer by Mr.doob.

Usage Instructions

Currently, there is no settings panel. All you need is the syntax for the shortcodes explained below.

Audio
Basic syntax: [audio src="File URL/path"]
Advanced syntax: [audio src="File URL/path" options="special string" id="string"]

Example:
[audio src="http://myblog.com/wp-content/uploads/2009/09/mysong" options="autoplay loop controls" id="header-audio"]

  • src is required. It must be an absolute or relative path to audio with the file name (“mysong”, in the above example). The files need to be located somewhere in your content folder (usually ‘wp-content’) unless you specify the files using the format option. File extension can be omitted. Upload “mysong.mp3”, “mysong.ogg” etc. as applicable to the specified location.
  • options is optional. It is a space-separated list of attributes defining the player behavior: autoplay to start playback automatically; autobuffer to start preparing the playback, controls to display the built-in playback controls (otherwise you can build and hook up your own), and loop to start from the beginning when the end is reached. The default value is "controls autobuffer".
  • id is optional. If you do not include one, the audio tag will have an automatically generated ID of html5audio-number. The IDs for the Flash players are prefixed with f-.
  • format is optional. It is a space-separated list of available file formats. The default value is auto which autodetects the formats. You can specify a list of available formats manually instead (e.g. format="ogg mp3 wav").

Video
Basic syntax: [video src="File URL/path"]
Advanced syntax: [video src="File URL/path" width="pixel size" height="pixel size" options="string" id="string" only="H.264"]

Example:
[video src="http://myblog.com/videos/vidclip" poster="http://myblog.com/wp-content/uploads/2009/09/clip-teaser.jpg" width="320" height="240" options="autoplay" id="vid-1"]

  • src is required. It must be an absolute or relative path to video with the file name (“vidclip”, in this example). The files need to be located somewhere in your content folder (usually ‘wp-content’) unless you specify the files using the format option. File extension can be omitted. Upload “vidclip.ogg” (in Ogg Theora format) and “vidclip.m4v” (in mp4 format) to the specified location.
  • poster is optional. It is an URL to the image you want to display before the video loads/starts playback.
  • width and height are optional. The default size is 480×320 (resolution of iPhone which does support embedded videos on pages).
  • options is optional. It is a space-separated list of attributes defining the player behavior: autoplay to start playback automatically; autobuffer to start preparing the playback, controls to display the built-in playback controls (otherwise you can build and hook up your own), and loop to start from the beginning when the end is reached. The default value is "controls autobuffer".
  • id is optional. If you do not include one, the video tag will have an automatically generated ID of html5video-number. The IDs for the Flash players are prefixed with f-.
  • format is optional. It is a space-separated list of available file formats. The default value is auto which autodetects the formats. You can specify a list of available formats manually instead (e.g. format="ogg m4v").

If you find this plugin useful, you can rate it and link to this page. If you don’t like it for some reason or have suggestions, feel free to leave feedback and comments on this page.

Manual Installation

  1. Download the file and upload the unzipped folder degradable-html5-audio-and-video to your plugins directory.
  2. Activate the plugin through the ‘Plugins’ menu in WordPress
  3. And then follow the usage instructions above

Frequently Asked Questions

If your files do not play properly, check the following points:

The final html code looks fine but doesn’t play in Firefox/Safari
The server needs to be configured to serve the video files with the proper MIME type. (Setting the type through HTML code alone is not sufficient.) On a Linux host, you can add the following lines to the .htaccess file:
AddType video/ogg ogg
AddType video/mp4 mp4

Are there limitations on formats and extensions?
The plugin requires specific file formats and extensions. Partly, this is because the current support in browsers is limited. E.g. Firefox 3.5 will not play the Ogg video unless the video has the extension .ogg (.ogv would not play). Follow the instructions for the best results. If you do not wish to create two versions of video (using e.g. ffmpeg2theora), and you provide only the H.264 file, the plugin will detect this and will use JavaScript to play the file in Firefox using the fallback player.

The plugin does not recognize the location of the files
This should not happen if you follow the instructions. The current version of the plugin will fail if you link to the audio or video using the attachment ID. If you store the files on a different server, use the format option to manually specify the available file formats; this bypasses the autodetection that requires the files to be present within the content directory of WordPress.

Can I change the look or behavior of the fallback players?
For audio, you can. Refer to the available options and add lines to the file degradable-html5-audio-and-video.php under the heading Format the player by inserting lines here.

Changelog and Roadmap

Feel free to leave comments with requests for features or changes. My goal is to keep the plugin lightweight but I am open to ideas.

1.6.0

  • For audio, you now do not need to provide the Ogg files (This uses JavaScript to force Firefox to the Flash fallback.)
  • New format option to manually specify available file formats (avoids auto-detection and allows storage anywhere)

1.5.1

  • For video, you now do not need to provide the Ogg Theora files. If only H.264 version is available, Firefox will be served with the Flash fallback.
  • Due to the auto-detection involved, video files should be somewhere under your content folder (usually ‘wp-content’). UPDATE: Unless you use manually override this (using v.1.6.0).

1.4.2

  • Compatibility with WordPress 2.9 and 2.9.1

1.4.1

  • The width and height of the HTML5 video element is now explicitly set

1.4.0

  • The autoplay and loop options (if used) are also applied to the Flash fallback audio player
  • The plugin accepts relative paths (e.g.`/wp-content/uploads/2009/09/new_world` in addition to `http://soukie.net/wp-content/…`)
  • If the path and name to media includes the file extension (‘.mp3′ etc.), it will be ignored and the media will function properly

1.3.0

  • Fixed a problem with the audio Flash player introduced by incorrect upload of v1.2 (affected some users). Apologies!
  • Switched to a three-digit version numbering.

v1.2

  • The audio files no longer need to be under the ‘uploads’ directory but anywhere within your content (usually ‘wp-content’).
  • Updated the way IDs are applied to the fallback Flash players (they use the supplied or generated ID prefixed with ‘f-’).

v1.1

  • Added optional attribute options to define the player behavior (default is: show built-in controls, buffer media when page loads but do not start autoplay and do not loop).
  • Added support for .wav (wave) audio (the preferred source, if present).
  • Fixed bug with incorrect IDs of the fallback Flash players.
  • Expanded documentation to cover available codecs, Google Chrome 3.0 and options.

v1.0

  • Initial version.

52 Comments »

feed icon Feed

thank u for this plugins , i really needet that :)

Andreas Koutsoukos, September 22, 2009:

Hello.
I just try to test te plugin, but there is something bug.

I just write blog post and in the html i write this
[audio src="http://www.skenevisuals.com/andreas/wordpress/wp-content/themes/blogi/audio/test" options="autoplay loop controls" id="header-audio"] but in the site it says this “No audio files uploaded, make sure you added it as audio.” what i do wrong.

Pavel Soukenik, September 22, 2009:

Hello Andreas, there was a limitation for [audio] that the file needed to be somewhere in the “uploads” directory of your WP content. I fixed this to allow audio anywhere within the content directory. (The plugin did and does allow for custom name of the wp-content.) Thanks for pointing this out!

shareAll, September 22, 2009:

After installing on Wordpress page, I get preloader but no audio loads.

I’m using an mp3 file in the uploads directory.

[audio src="http://www.pameladunn.org/wp-content/uploads/BrightFuture" options="controls autobuffer" id="header-audio"]

Any suggestions?

Pavel Soukenik, September 22, 2009:

It seems you did not provide an .ogg version; so it will only work with Safari or Chrome but not in Firefox. (And Explorer should use the Flash player anyway). There are many tools that allow you to convert an MP3 to OGG. Simply create the .ogg version with the same name and upload to the same folder as the MP3. Hope this helps.

Just a side note that [audio src="http://www.pameladunn.org/wp-content/uploads/BrightFuture"] should be sufficient for you. (controls and autobuffer are the default when you leave out the options, and unless you plan to specially control or format the players, you do not need to specify the ID either).

Paulius, September 23, 2009:

I added poster, but with Firefox 3.5.3 I can’t see it. Firstly I thought that .png format is not supported, but .jpg did not help me.
Any suggestions?

Pavel Soukenik, September 23, 2009:

Unfortunately, Firefox will support the poster attribute only from version 3.6. Also, the HTML5 working draft specifies that the browsers (after the video media loads) can choose to display either the poster, or the first frame of video “at [their] discretion.” (Which I think is unfortunate; e.g. Safari supports ‘poster’ and switches to the first frame when it can.)

mike, September 23, 2009:

Hi there,
I’m testing this out for a site at the mo to play mp3’s, it works well and looks great (kudos) except that the ‘options’ don’t seem to get implemented- they are left hanging in the audio tag. Any thoughts? cheers!

Pavel Soukenik, September 23, 2009:

Hi Mike, that is actually on purpose. If you’re looking at the generated HTML, and see something like audio autoplay loop controls id="html5audio-0" … at the beginning, that’s perfectly fine and proper syntax. (This example would be the result of specifying options="autoplay loop controls" as part of the shortcode.)

Adam Zaninovich, September 29, 2009:

On my text server, the plugin was working great. Not so much after moving to wordpress linux hosting. I have both m4a and ogg copies of the files (working on mp3) but they don’t load on safari4 or ff3.5. When I look at the generated code, it only has the line for an mp3 file… m4a and ogg are missing. What’s wrong? As a test I wrote a correctly formatted html5 audio page to make sure the server can serve up the correct file types. Check it out if you want: http://thezanino.com/test/

Pavel Soukenik, September 30, 2009:

Hi Adam, can you send me the complete text of the shortcode you were using? It seems the plugin has trouble verifying the existence of the m4a and other versions. And yes, I checked the test page you created and it’s working fine. Thanks for being persistent! Update: We diagnosed it and it was caused by not using the exact required syntax for the “src”. That being said, the new version now allows relative paths and tolerates file extensions.

VVOR, October 2, 2009:

STUNNING PLUG ! Tnx

Vlad, October 7, 2009:

Halla everyone.
I just installed the player, also uploaded the mp3 file and ogg file into uploads folder but it doesn’t work.
The browser sees the player, but it gets an error like: Connecting… File not found.
Any suggestions ? What can be done ?

Pavel Soukenik, October 7, 2009:

Hi Vlad, can you email me with the text of the shortcode you are using in the post?

Jordi Petit, October 8, 2009:

Hello,

I have a bug report on v1.4.0: Handling of audio files is incorrect, as the $filename is not constrcuted correctly.

The following lines do now work for something like [audio src="/audio/file"], whereas the [video] handler works well in this case (its code is much simpler).

Pavel Soukenik, October 8, 2009:

Hi Jordi, the audio code needs to check for the existence of the possible files (wav, mp3, ogg…). As a limitation, the file must be located somewhere in your wp-content. It should work correctly with both absolute and relative paths, and also with custom locations of the content directory. Let me know if this is not working for you.

Jordi Petit, October 8, 2009:

Hello. Another bug report

In videos, width and height are not taken into account (at least under firefox 3.5). Solutions is simple:

$output = ‘<video width='.$width.' height='.$height.' '. $options;

Pavel Soukenik, October 8, 2009:

You are correct, the size was not explicitly set and was taken from the poster/video file. I have fixed it so you can now override the size. (I had overlooked this code was defined only for the fallback player.)

Adam, October 10, 2009:

Tried to embed a Youtube video on my site. It appears to show the player controls at first and then it gets lost with a big x in the middle. Here is my shortcode: [video src="http://www.youtube.com/watch?v=IOIJHh3mKcQ" poster="http://i2.ytimg.com/vi/IOIJHh3mKcQ/default.jpg" width="380" height="344"]

Looks like a great plugin!

Pavel Soukenik, October 11, 2009:

Hi Adam, unfortunately, this plugin is not designed to embed YouTube. Technically, it could be done but without the ogg format present, the value would be limited. I would recommend that you use one of the YouTube plugins for that, and my plugin for your own videos.

John, October 21, 2009:

Hi I’ve installed your plugin and have tested it with an mp3 I had lying around. It seems to work in everything on PC, but with firefox 3.5.3 on my macbook I get a dark grey box with a faint ‘x’ in the middle. Other browsers on the mac seem fine. HTML and PHP I can handle, but I have no idea about audio files. Any ideas? Cheers.

Pavel Soukenik, October 25, 2009:

Hi John, sorry for the late reply. You need to convert the mp3 to an ogg format and save it in the same location. Firefox does not support mp3 playback in native HTML5. See the format compatibility table.

wille, October 28, 2009:

Would be cool if the plugin had support for audio located in others servers. I prefer update great files in public servers, like archive.org.

Pavel Soukenik, October 29, 2009:

Thanks for the suggestion. I’ll think about a good way to do that and will implement this in the next update.

Shazron, October 30, 2009:

Awesome plugin – just reporting an OS quirk:

When I set the poster attribute for video, on Leopard h.264 plays fine under Safari 4.0.3.

However on Snow Leopard with Safari 4.0.3, when the poster attribute is set, playing h.264 only shows the poster, and the video cannot be played.

My guess is this is a quirk with Quicktime Player X.

Ben, November 13, 2009:

Neat plugin, though I question your choice of FLV player; it doesn’t keep parity with the browser-native players– no play/pause/stop buttons, no time, no loading indicators.

Might I suggest OS-FLV?

Pavel Soukenik, November 13, 2009:

Thanks for the suggestion Ben! I took a look at the plugin (because I would also love a better-featured fallback player for the video) but it does not seem to support either .m4v (H.264) or .ogg (Ogg Theora) format and therefore, for it to work as a fallback to HTML5 formats, you would need to supply yet another version of the video file. Anyway, let me know if I overlooked the m4v or ogg support, or if you run across any other suitable player. Thanks again!

Markus, November 19, 2009:

Thanks for your plugin! It works great in FF, Opera, Safari an IE. But the flash-player doesnt wrap right and looks not very nice. Did you test it?

And: it ist possible to style mye own flash-player/use another flash-player?

Thanks for your time & work!
Markus

Pavel Soukenik, November 19, 2009:

Hi Markus, is the first issue related to the audio or video Flash player? For styling the player, see the answer in FAQ (above). Currently, it is not possible to use your own player without modifying the plugin. Do you have any suggestions for alternative players? Thanks, Pavel

JSDK, November 21, 2009:

in my site, mp3 and movies don’t load ;/ Firefox and Chrome pls help http://jsdk.pl

np http://jsdk.pl/index.php/moje/rapowanie/zniszczony-przez-wojne/

Christiaan, December 1, 2009:

Hi Pavel, what should I be doing if I want to add a style class to the video tag, such as for aligning the video on my page?

If I add it to the shortcode it seems to get removed by the plugin. Any ideas?

Christiaan, December 13, 2009:

It would be nice to have some settings to alter the text people see when they can’t view the video.

doeme, January 5, 2010:

hi

i tried to use your plugin on my blog. when i implement a mp3 file from another website it works, but not with files from my page, i only see a big X.

when i try to show a video, i only get “[ERROR: No URL was passed to the generic video BBCode]”

what am i doing wrong :( ?

Patrick, January 6, 2010:

You know what would be great? A plugin to automatically convert M4V to OGG, or the other way round, depending on what you upload. Of course that would need ffmpeg or something like that on the server, but it could be done. It would be extremely useful in conjunction with this plugin. Maybe it could even be built into this plugin?
Anyway, love it! Thanks for the great work!

Pavel Soukenik, January 16, 2010:

Sorry for not responding for so long!
@JSDK and @doeme: I’ll get in touch with you via email.
@Christiaan: Good points. For styling, you can assign the your own ‘id’ (or use the generated one) and use that to style video in CSS. For message, do you mean the “Could not use HTML 5 or Flash for playback…”?
@Patrick: Thanks! Programming what you suggest is beyond my skills. And it would likely be too intense to carry out in real-time. Let me know if someone does this.

Flo, January 23, 2010:

hi,
thanks for the plugin, that is exactly what I was looking for.

I would have a feature request, it would be nice if the fallback variants could be choosen by the user. i.e. I don’t want to encode my videos in different formats, I just provide the ogg version, and all people with a browser not capable of viewing it, should get a simple download link.

so, a little form, where you can arrange the fallbacks in order or disable it at all, with custom text to show if disabled, would be my idea.

Pavel Soukenik, January 23, 2010:

Yes, this is a good suggestion! It’s not that difficult, so I am going to implement this in the next couple of days.

Nate Steiner, January 28, 2010:

I’d love to use this plugin, but hosting video files on the same server as my WP is a no-go for me. Is there a way to turn off the auto-detect so I can point to files on an S3 server or whatnot? Excellent work regardless!

Pavel Soukenik, January 28, 2010:

I see. I will adapt it so you could override this and provide the list of available formats manually (for both video and audio).

Pavel Soukenik, January 28, 2010:

The download on this page is now 1.6.0. It allows leaving out ogg also in audio, and if you need to store media files anywhere, use the optional manual specification of formats: [video
src="http://file.goes/here" format="ogg m4v"] [audio
src="http://file.goes/here" format="mp3 ogg m4v"]
. Documentation update and automatic upgrade coming soon.

CoSTa, February 1, 2010:

Hello
I’m trying to use your plugin but I have problems. It works under Firefox and Safari but when it comes to Flash (Opera, IE), the Flash player does not load :/. IE anounces an error in format like this: http://img.skitch.com/20100201-xm5w2arxganc64ir3tqnnbf1pt.jpg (I know, it’s in Polish but you should be able to figure out what it says).

I don’t know how to solve this problem. Please, help!

Pavel Soukenik, February 1, 2010:

CoSTa, can you put it on a page (so it’s not visible as a post) and mail me a link to it together with the shortcode used? I’ll check it.

Bill, February 2, 2010:

Using the latest version, all I can get is:
[ERROR: No URL was passed to the generic video BBCode]

My Page:
http://ripple.ca/?page_id=3786

Can you help? Thanks.

Pavel Soukenik, February 2, 2010:

I don’t see any video or error message but from the code, it seems you might have a conflict with the Viper’s video plugin. I will email you a “renamed” version to see if it will work then.

Bill, February 3, 2010:

Thank you for your fast reply, Pavel! I think you are right about the Viper conflict. The plugin works now for Safari but does not yet fall back to Flash in Firefox. I am going to try an ogg version of my video and see if that makes Firefox happy. Your help is much appreciated.

CoSTa, February 3, 2010:

Thank you Pavel for the fast reply! It seems like the last update solved my problem. Now for some more testing with IE and if it will be all right, off we go with you plugin :)

Thanks and good work!

Trackbacks/Pingbacks

Your comment