1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-30 05:19:57 +00:00

Add audio parser for handling audio content

This commit is contained in:
Jermolene 2014-10-18 14:50:07 +01:00
parent ea3bdb5556
commit 2ffe53f191
6 changed files with 69 additions and 0 deletions

View File

@ -1759,6 +1759,8 @@ $tw.boot.startup = function(options) {
$tw.utils.registerFileType("image/svg+xml","utf8",".svg",{flags:["image"]}); $tw.utils.registerFileType("image/svg+xml","utf8",".svg",{flags:["image"]});
$tw.utils.registerFileType("image/x-icon","base64",".ico",{flags:["image"]}); $tw.utils.registerFileType("image/x-icon","base64",".ico",{flags:["image"]});
$tw.utils.registerFileType("application/font-woff","base64",".woff"); $tw.utils.registerFileType("application/font-woff","base64",".woff");
$tw.utils.registerFileType("audio/mp3","base64",".mp3");
$tw.utils.registerFileType("audio/mp4","base64",[".mp4",".m4a"]);
$tw.utils.registerFileType("text/x-markdown","utf8",[".md",".markdown"]); $tw.utils.registerFileType("text/x-markdown","utf8",[".md",".markdown"]);
// Create the wiki store for the app // Create the wiki store for the app
$tw.wiki = new $tw.Wiki(); $tw.wiki = new $tw.Wiki();

View File

@ -0,0 +1,37 @@
/*\
title: $:/core/modules/parsers/audioparser.js
type: application/javascript
module-type: parser
The audio parser parses an audio tiddler into an embeddable HTML element
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
var AudioParser = function(type,text,options) {
var element = {
type: "element",
tag: "audio",
attributes: {
controls: {type: "string", value: "controls"}
}
},
src;
if(options._canonical_uri) {
element.attributes.src = {type: "string", value: options._canonical_uri};
} else if(text) {
element.attributes.src = {type: "string", value: "data:" + type + ";base64," + text};
}
this.tree = [element];
};
exports["audio/mpeg"] = AudioParser;
exports["audio/mp3"] = AudioParser;
exports["audio/mp4"] = AudioParser;
})();

View File

@ -0,0 +1,3 @@
title: Caruso - Ave Maria
type: audio/mp3
_canonical_uri: https://archive.org/download/Caruso_part1/Caruso-AveMaria.mp3

View File

@ -0,0 +1,2 @@
title: TiddlyWiki.mp3
type: audio/mp3

View File

@ -0,0 +1,25 @@
created: 20141018131647392
modified: 20141018132325901
tags: [[Working with TiddlyWiki]]
title: Audio
type: text/vnd.tiddlywiki
Audio files can be incorporated into TiddlyWiki in a very similar way to [[images|Images]].
! Embedded Audio
Small audio files can be embedded directly within TiddlyWiki. Embedding isn't suitable for large files (over a few hundred kilobytes) because it increases the size of the TiddlyWiki file.
For example, the tiddler [[TiddlyWiki.mp3]] contains an MP3 recording of the word "TiddlyWiki". Viewing the tiddler directly should show an audio player that allows playback.
You can also transclude audio files. For example:
<<wikitext-example-without-html '{{TiddlyWiki.mp3}}'>>
! External Audio
External audio tiddlers use the ''_canonical_uri'' field to point to an external audio file, and have a block ''text'' field. This reduces their size considerably, and still allows for playback.
For example, the tiddler [[Caruso - Ave Maria]] points to an online audio recording hosted on http://archive.org:
<<wikitext-example-without-html '{{Caruso - Ave Maria}}'>>