Skip to content

Instantly share code, notes, and snippets.

@telamon
Created February 14, 2012 22:15
Show Gist options
  • Save telamon/1830988 to your computer and use it in GitHub Desktop.
Save telamon/1830988 to your computer and use it in GitHub Desktop.
Quick'n'Dirty FlodJS implementation.
window.gobmod={};
window.gobmod.attachPlayer = function(elem){
elem = $(elem);
var player = new Element('a',{'class':'modplaybutton', href: '#'});
player.innerHTML='>'
elem.insert({top: player});
// Start playback
var startPlayback=function(){
stopPlayback();
player.innerHTML='<img src="/images/loading.gif">';
var xhr = new XMLHttpRequest();
xhr.open('GET', elem.dataset.url, true);
xhr.responseType = 'arraybuffer';
xhr.onload = function(e) {
if(this.status == 200){
var uInt8Array = new Uint8Array(this.response);
window.gobmod.player= window.neoart.F2Player(null);
window.gobmod.player.load(this.response);
window.gobmod.playing = elem.dataset.url;
window.gobmod.playbutton = player;
player.innerHTML = '#';
window.gobmod.player.loopSong=1;
window.gobmod.player.play();
}else{
player.innerHTML= 'X';
}
};
xhr.send();
};
// Stop playback
var stopPlayback = function(){
window.gobmod.playing = null;
if(window.gobmod.player != null){
window.gobmod.player.stop();
}
if(window.gobmod.playbutton != null){
window.gobmod.playbutton.innerHTML = '>';
}
}
// On Click
player.observe('click',function(ev){
if(window.gobmod.playing == elem.dataset.url){
stopPlayback();
}else{
startPlayback();
}
ev.stop();
});
};
window.gobmod.init = function(ev){
window.gobmod.player=null;
window.gobmod.playing=null;
$$('.modfile').each(function(i){ window.gobmod.attachPlayer(i)});
};
document.observe('dom:loaded',window.gobmod.init);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment