Halloween Animation with Audio

by JayNick - uploaded on October 20, 2017, 11:57 pm

Animated Halloween SVG image with embedded audio file using a Base64 encoded data URI. Audio is a snippet of a file licensed CC0 from freesound.org It is coded to loop repeatedly.



Works on a Mac with desktop browsers, Firefox, Chrome, and Safari. Expect it to work on Windows and Linux, but did not test. It did not work with IOS mobile browsers Safari and Firefox.



Could not get to work using SVG's audio element, but worked with SVG's foreignObject element containing an HTML audio element.



Please leave a comment if tested in another environment - working or not - or if there is a better way to do this. Thanks.

Log in to add this clipart to a collection.

Tags
audio broom cartoon child comic Comic characters costume cute female ghost girl grey halloween hat Holidays & Special Days magic orange pumpkin purple request+completed scene SMIL STEAMcoded.org sweets symbol twins
Safe for Work?
Yes
Download SVG

Comments

Nice one!
The first svg I've seen with sound. Works on win with chrome&firefox.
Edge has the audio working, but not the animation.

There is a "flick" in the sound, not sure if it's supposed to be there or just a "rendering" "feature".

Thanks for checking on Windows browsers.

The sound clip was to long, so I spliced beginning and end. I should have paid more attention to the quality, but I didn’t hear it with my poor hearing and testing with low volume.

Works with 64-bit Opera 42.0, too (on a Windows 10 laptop).

The thumbnail doesn't render? nice one though :)

cool. looks good

What did you use to turn the audio file to mpeg and how could you encode it to base64? Trying notepad++ to decode your file but can't seem to get a valid mpeg.
Also somehow embedding base64 encoded mp3 is ignored by the browsers. Is mpeg the only way to go?

In Notepad++ select everything in the Base64 starting with the //uQZ all the way to the final qo= (but not the ">), copy it, open a new document, paste it in that document, press ctl-v to select everything, convert from Base64, save as new.mpg (or witch.mpg, or anything.mpg), and you have it. VLC plays it, I have not tested other players, but they should play it, too.

@Lazur URH - I used Audacity to crop the sound file and save it as an mp3, then used Mac command line tool, uuencode, to generate the base64 data. Reference https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs
I used mp3 (mime type: audio/mpeg) because it is the only format supported by all the major browsers. Reference https://www.w3schools.com/html/html5_audio.asp

@JayNick Interesting. Was looking at the codes but the media type mpeg got me confused.
Now figuring out how to add that smil animation... and if it can be triggered by clicking on an object.

@Lazur URH Yes you can trigger SMIL animation by clicking on an object. Use the beginElement() method. Reference https://developer.mozilla.org/en-US/docs/Web/API/SVGAnimationElement

Log in to comment.