Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@binux
Created November 16, 2012 14:32
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save binux/4087765 to your computer and use it in GitHub Desktop.
Save binux/4087765 to your computer and use it in GitHub Desktop.
playlist for moe.fm
var _playlist = [];
var _next = '';
var _loading = false;
var _loaded = false;
var _current = 0;
function _load_more() {
if (_loading) return;
_loading = true;
$.get(_next, function(result){
_loading = false;
_next = result.info.next_url;
result.playlist.forEach(function(e, n) {
$('#playlist').append('<tr class="song" id="song-'+e.sub_id+'"><td>'+e.wiki_title+'</td><td>'+e.title+' /'+e.artist+'</td><td><a href="javascript:void(0);" onclick="_play('+_playlist.length+', '+n+');">play</a></td>');
});
_playlist.push(result.playlist);
}, 'json');
}
function _play(list, music) {
player.setPlaylist(_playlist[list]);
player.play(music);
_current = list;
}
function load_playlist() {
if (_loaded) return;
_loaded = true;
_next = playerOpt.listInfo.info.next_url;
playerOpt.isLoadedList = true;
playerOpt.listInfo.tempList = null;
player.onResume(function() {
$(".song").attr("style", "");
$("#song-"+player.getClip().sub_id).attr("style", "color: blue;font-weight: bold;");
if (_current+1 >= _playlist.length) {
_load_more();
}
});
player.onFinish(function() {
if (player.getClip().index+1>=player.getPlaylist().length && _current+1 < _playlist.length) _play(_current+1, 0);
});
$("#page").append('<section><div class="wrap"><table><tbody id="playlist"></tbody><tfoot><tr><td colspan=3><a href="javascript:void(0);" onclick="_load_more()">load more</a> / <a href="javascript:void(0);" onclick="player.reset();">reset player</a><td></tr></tfoot></table></div></section>');
_playlist.push(player.getPlaylist());
_playlist[0].forEach(function(e, n) { $('#playlist').append('<tr class="song" id="song-'+e.sub_id+'"><td>'+e.wiki_title+'</td><td>'+e.title+' /'+e.artist+'</td><td><a href="javascript:void(0);" onclick="_play(0, '+n+');">play</a></td>'); });
$('.player-button.button-next').die("click").live('click',function(){
if($(this).hasClass('disabled')){
return false;
}
$(this).addClass('disabled');
$('.playlist_title').html('Loading...');
$('.playlist_wiki_title').html('');
$('.playlist_fav_wiki').hide();
$('.playlist_cover img.cover').attr('src',siteurl+'public/images/fm/cover_medium.png');
if(player.getClip().index+1<player.getPlaylist().length){
player.play(player.getClip().index+1);
} else {
if (_current+1 < _playlist.length) _play(_current+1, 0);
}
});
}
$(function() {
console.log(player);
if (playerOpt.listInfo.info) {
load_playlist();
} else {
var _initPlaylist = initPlaylist;
initPlaylist = function() {
_initPlaylist();
load_playlist();
}
}
});
@binux
Copy link
Author

binux commented Nov 16, 2012

bookmark:

javascript:void((function(){var d=document;var s=d.createElement('script');s.src='https://raw.github.com/gist/4087765/5505db27b1feaec42bdf183d179cb00729e5d1bc/playlist.js';s.id='binux_js';d.body.appendChild(s)})())

@binux
Copy link
Author

binux commented Nov 16, 2012

updated bookmark:

javascript:void((function(){var d=document;var s=d.createElement('script');s.src='https://raw.github.com/gist/4087765/playlist.js';s.id='binux_js';d.body.appendChild(s)})())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment