Created
October 21, 2016 17:16
-
-
Save dinjas/c6bcdbcbdc8825ed7dd42c3adf722f5d to your computer and use it in GitHub Desktop.
adspot js pre-coffee conversion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function() { | |
var $podcast_url, $preview_ele, createMediaElement, showError; | |
$preview_ele = $('[data-id="preview"]'); | |
$podcast_url = $('[data-id="podcast_url"]'); | |
/** | |
* Creates the mediaelement object | |
* @param {Boolean} silent Whether to auto play when mediaelement is created | |
*/ | |
createMediaElement = function(silent) { | |
var mediaElement; | |
mediaElement = new MediaElementPlayer('#audio_element', { | |
alwaysShowControls: true, | |
features: ['playpause', 'progress', 'current', 'duration'], | |
audioWidth: 286, | |
success: function(mediaElement, domNode) { | |
if (!silent) { | |
mediaElement.play(); | |
} | |
}, | |
error: showError | |
}); | |
}; | |
showError = function() { | |
var $ele; | |
$ele = $('<div>').append('Unable to find a downloadable MP3 at this URL').css({ | |
'font-size': '0.5em', | |
'font-weight': 'normal' | |
}); | |
$preview_ele.html($ele); | |
}; | |
$podcast_url.on('blur', function() { | |
var path, tag; | |
$preview_ele.empty(); | |
path = $(this).val(); | |
if (!path.trim()) { | |
return false; | |
} | |
if (!path.match(/http/)) { | |
showError(); | |
return false; | |
} | |
tag = '<audio id="audio_element" src="' + path + '" controls="controls"></audio>'; | |
$preview_ele.html(tag); | |
createMediaElement(false); | |
}); | |
$podcast_url.on('focus', function() { | |
$preview_ele.empty(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment