Skip to content

Instantly share code, notes, and snippets.

@hauntedhost
Last active December 16, 2015 14:09
Show Gist options
  • Save hauntedhost/5446270 to your computer and use it in GitHub Desktop.
Save hauntedhost/5446270 to your computer and use it in GitHub Desktop.
wordpress soundclip player for "raisin" the dog
<script type="text/javascript">
jQuery(document).ready(function(){
// soundclip player
<?php
$raisin_id = get_latest_raisin_id();
$mp3_id = get_post_meta($raisin_id, "raisin_mp3_id", true);
$mp3_url = wp_get_attachment_url($mp3_id);
$ogg_id = get_post_meta($raisin_id, "raisin_ogg_id", true);
$ogg_url = wp_get_attachment_url($ogg_id);
if (!empty($mp3_id) && !empty($ogg_id)) : ?>
jQuery.browser = {};
jQuery.browser.mozilla = /mozilla/.test(navigator.userAgent.toLowerCase()) && !/webkit/.test(navigator.userAgent.toLowerCase());
jQuery.browser.opera = /opera/.test(navigator.userAgent.toLowerCase());
var audioElement = document.createElement('audio');
if (jQuery.browser.mozilla || jQuery.browser.opera) {
audioElement.setAttribute('src', '<?php echo $ogg_url; ?>');
} else {
audioElement.setAttribute('src', '<?php echo $mp3_url; ?>');
}
jQuery('.raisin_play').click(function() {
audioElement.play();
});
<?php endif; ?>
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment