Recently, My father got an iPad; it's his one internet-enabled device. He mentioned that he couldn't listen to any of the audio on my site. Well, I found this to be unacceptable, and, while we still on the phone, I made the following changes to Drupal's Audio Module:
1. Add a class and title to the flash player.
FIrst, edit the "1pixelout.inc" file in the audio/players/ directory (or edit the .inc file for the play you have chosen to use.) Add the following class to the flash object tag: class="1pixelflashplayer". Also, add the following title attribute to the object tag: title="{$options['soundFile']}".
2. Add javascript to the page
The following javascript will search for all the flash players with the aforementioned class, hide them, and insert an <audio> tag after them with the src of the video from the flash player. Note: This will only work for mp3 audio files. You can download the javascript at the bottom of the page.
I Hope this helps someone. Javascript follows...
$(document).ready(function() { try { myAudioObj = new Audio(""); audioObjSupport = !!(myAudioObj.canPlayType); basicAudioSupport = !!(!audioObjSupport ? myAudioObj.play : false); if (myAudioObj.canPlayType) { canPlayMp3 = ("no" != myAudioObj.canPlayType("audio/mpeg")) && ("" != myAudioObj.canPlayType("audio/mpeg")); } } catch (e) { audioObjSupport = false; basicAudioSupport = false; } if (canPlayMp3) { $('.1pixelflashplayer').each(function(index) { var $player = $(this); $player.hide(); var url = $player.attr('title'); $player.after('<audio controls="controls" src="'+url+'" ></audio>'); }); } });
| Attachment | Size |
|---|---|
| html5audio.js.txt | 673 bytes |

Comments
mobile player size
Hi- I was wondering if there is a way to add height and width attributes to the mobile player. When I try to load it on the iPhone, the "streaming..." text is larger than the player. Any suggestions? The functionality itself is great, thank you! Chris
You can set the height and
You can set the height and width as attributs on the audio tag. I'm not sure if mobile Safari will obey though. Since Safari is choosing the width, by default, and is inserting the "Streaming" text, I'd guess that the display problem is a bug. I also notice it on my iPhone - iOS 4.2
Brian
Post new comment