[Seaside] How to best detect browser for audio tag differences

Johan Brichau johan at inceptive.be
Wed Aug 4 09:54:37 UTC 2010

Hi Tim,

You might also want to check out the Modernizr javascript library: http://www.modernizr.com/ 
In particular, the section on html5 audio formats: http://www.modernizr.com/docs/#audioformats

Modernizr detects the abilities of your browser w.r.t. html5.
However, instead of dispatching on the userAgent property of the request, you will need to transport the result value of a javascript expression back to the server so you can dispatch on it. For an ajax callback, that is not a problem, but I'm unsure what the best strategy would be for handling that in a full page request.

On 03 Aug 2010, at 01:48, Tim Mackinnon wrote:

> Hi guys - I've looked through suggestions for browser detection on the list - but am unsure what the best approach is to handle the differences between how browsers handle the audio tag in html5.
> I don't need to support all browsers (and part of this is education for me) - but I particularly notice that Firefox supports ogg and wav media while safari supports mp3 (damn those committees).
> My best attempt so far is below - but I wonder if this is the best way to go about it (is there a better way of detecting a browser type? I saw that jQuery has something - is it better to use it - and do something on a page load script to set the src attribute of a single audio tag?).
> myRequest := self requestContext request. "for debugging - but confused the hell out of me that I needed a variable"
> (myRequest userAgent beginsWith: 'Mozilla')
> 		ifTrue: [
> 			(html audio)
> 				url: (MyLibrary default urlForFile: 'sound.wav');
> 				id: 'noise' ]
> 		ifFalse: [
> 			(html audio)
> 				url: (MyLibrary default urlForFile: 'sound.mp3');
> 				type: 'audio/mpeg';
> 				id: 'noise' ].
> html
> 		form: [
> 			(html button)
> 				onClick: ((html jQuery id: 'noise') each: (JSStream this call: 'play'));
> 				with: 'Do It'.
> 		 ].
> thanks,
> Tim
> _______________________________________________
> seaside mailing list
> seaside at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside

More information about the seaside mailing list