I have an SVG with some basic javascript interactivity, and I would love to be able to put some audio into it as well.
To clarify:
Any insight on how this could be accomplished?
The default event-base element for all SVG media elements is the element itself. The following elements are media elements: 'audio' 'video'
Scalable Vector Graphics (SVG) are an XML-based markup language for describing two-dimensional based vector graphics.
Embedded content is content that imports into the document from another resource. SVG <image> and <foreignObject> elements are used for SVG embedded content support.
If you require a browser with support for HTML5 audio, then it's possible to just put the audio elements in the svg (use the XHTML namespace for the audio element and its children). Last time I tried it didn't require a foreignObject wrapper. Here's an example showing how to do that (works in chrome, firefox and opera).
It's also possible to create HTML5 audio elements with javascript and use them inside the SVG.
There are SVG <audio>
and <video>
element tags defined in SVG 1.2 Tiny. Opera supports them but no other UA does as yet.
A solution that will work most places except IE 9/10 would be to use a <foreignObject>
element with an html <audio>
element as a child.
I don't think there's a good answer if you need IE9/10 support as it doesn't support <foreignObject>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With