Embedding sound files

165 views
Skip to first unread message

Hubert

unread,
Jan 20, 2021, 5:35:41 AM1/20/21
to TiddlyWiki
Hi,

In this GG post, Eric presented a minimal use case for TW to play a sound on clicking a checkbox.

I would like to embed the mp3 (or ogg or any other compressed sound) file within TiddlyWiki instead of keeping it as an external source file.

We don't have any relevant tiddler content types for sound at the moment. Was anyone able to come up with a solution that works? Perhaps using binary data tiddlers?

Thanks in advance for sharing your ideas.

-Hubert

PS. Here's Eric's post for reference.

Try this:

1) Create a tiddler "DoneSound", containing:
<audio autoplay controls style="height:2em;width:10em;" >
  <source src="done.mp3" type="audio/mpeg">
</audio>

2) In your <$checkbox> widget, add a "checkactions" parameter, like this:
<$checkbox ... checkactions="""<$action-sendmessage $message="tm-notify" $param="DoneSound" />""">
   checkbox text goes here
</$checkbox>



Sylvain Naudin

unread,
Jan 20, 2021, 7:04:19 AM1/20/21
to TiddlyWiki
Le mercredi 20 janvier 2021 à 11:35:41 UTC+1, Hubert a écrit :

I would like to embed the mp3 (or ogg or any other compressed sound) file within TiddlyWiki instead of keeping it as an external source file.


Hello Hubert,


Tiddler TiddlyWiki.mp3 is set to audio/mp3 content type.


Cheers,
Sylvain

Hubert

unread,
Jan 20, 2021, 7:29:57 AM1/20/21
to TiddlyWiki
Thank you Sylvain.

I was able to embed the mp3 file and play it with a press of a button. Unfortunately, unlike in the case of "referenced" (external) files, autoplay doesn't seem to work for embedded files (I've checked that on TiddlyWiki.com as well).

When I put this into a tiddler and then open that tiddler, the sound does not play:

<audio controls autoplay>
  <source src="TiddlyWiki.mp3" type="audio/mp3">
</audio>


Is there anything else I'd need to do for autoplay to work for embedded files?

Thanks again,
Hubert

Saq Imtiaz

unread,
Jan 20, 2021, 7:41:08 AM1/20/21
to TiddlyWiki
Again untested code but try this:

<audio src={{{ [[data:video/mp4;base64,]addsuffix{TiddlyWiki.mp3}] }}} autoplay />

Hubert

unread,
Jan 20, 2021, 7:55:46 AM1/20/21
to TiddlyWiki
It worked! Thank you Saq.

Quick follow-up question: I've tested that on an mp3 file and it worked, even though you used "video/mp4" as data type. Is this data type universal for mpeg "specification" of files (mp3, mp4 etc, no matter if it's audio or video) or is this just a meaningless placeholder that will also accept non-mpeg filetypes, like ogg etc?

Regards,
Hubert

Saq Imtiaz

unread,
Jan 20, 2021, 10:05:29 AM1/20/21
to TiddlyWiki
I was copying from what I posted for someone else since I'm on my phone and it's hard to type wiki syntax.
Surprised that worked, I would have used audio/mpeg

As for other types you will just need to try, I have never looked into this much.

Hubert

unread,
Jan 20, 2021, 10:22:44 AM1/20/21
to TiddlyWiki
Thanks.

Since I last responded, I checked this on mobile using Tiddloid Lite.

The sound did not autoplay on mobile (whether it's audio/mpeg or video/mp4)

It did play on mobile when play was explicitly pressed on the mp3 tiddler, it's just that autoplay does not work for some reason.

Regards,
Hubert

Saq Imtiaz

unread,
Jan 20, 2021, 10:49:16 AM1/20/21
to TiddlyWiki
Odd. In Chrome on mobile (Android 10) and desktop (Win 10), autoplay works for me.

Hubert

unread,
Jan 20, 2021, 11:39:36 AM1/20/21
to TiddlyWiki
Can confirm. Chrome on Android works fine, so does Chrome and FF desktop (Windows).

It must be something to do with Tiddloid Lite, I might contact donmor on Github.

Thanks again Saq for all your help today.
Reply all
Reply to author
Forward
0 new messages