Commit ddae87a9 authored by Steel Wagstaff's avatar Steel Wagstaff

Adds support for links -> HTML5 audio elements

Turns links to web-published .mp3, .ogg, and .wav files into HTML5
audio elements
parent 96f96beb
...@@ -4,12 +4,11 @@ ...@@ -4,12 +4,11 @@
* Return an HTML5 audio player with the given src URL. * Return an HTML5 audio player with the given src URL.
*/ */
function mp3audio(src) { function audioElement(src) {
var html5audio = document.createElement('audio'); var html5audio = document.createElement('audio');
html5audio.id = 'audio-player'; html5audio.id = 'audio-player';
html5audio.controls = 'controls'; html5audio.controls = 'controls';
html5audio.src = src; html5audio.src = src;
html5audio.type = 'audio/mpeg';
return html5audio; return html5audio;
} }
...@@ -102,10 +101,10 @@ var embedGenerators = [ ...@@ -102,10 +101,10 @@ var embedGenerators = [
return null; return null;
}, },
// Matches URLs that have .mp3 in them (assumed to be audio files) // Matches URLs that end with .mp3, .ogg, or .wav (assumed to be audio files)
function html5audioFromMp3Link(link) { function html5audioFromMp3Link(link) {
if (link.href.toLowerCase().indexOf('.mp3') !== -1) { if (link.pathname.endsWith('.mp3') || link.pathname.endsWith('.ogg') || link.pathname.endsWith('.wav')) {
return mp3audio(link.href); return audioElement(link.href);
} }
return null; return null;
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment