/
music.js
83 lines (71 loc) · 2.25 KB
/
music.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*global jQuery:true, playerjs:true, $Player:true */
(function($, document, window){
var URLS = [
'https://soundcloud.com/smallenginerepair/serve-yourself-1',
'http://www.youtube.com/watch?v=ucHx3ucmVpk',
'https://vimeo.com/17103269',
'https://soundcloud.com/decemberavenue/breatheagain',
'http://www.youtube.com/watch?v=PNIR6jJTlJw',
'https://vimeo.com/35017675'
];
var $tracks = $('#tracks'),
players = [],
count = 0,
isReady = false;
var start = function(){
var index = 0;
var multi = new $Player(players);
// Set the callout.
multi.on('active', function(index){
$('.panel').removeClass('callout').eq(index).addClass('callout');
});
// Go to a track by clicking on it.
$('.panel').on('click', function(){
if (!isReady){
return false;
}
var index = $('.panel').index(this);
multi.play(index);
return false;
});
isReady = true;
};
// We need to wait for all the players to be ready before we go.
var onReady = function(){
count++;
if (count === URLS.length){
start();
}
};
$(document).on('ready', function(){
// Go get all the URLS from embedly and then embed them.
$.embedly.oembed(URLS, {query:{better: true} })
.done(function(results){
$.each(results, function(i, obj){
$tracks.append(['<li class="track">',
'<div class="panel">',
'<div class="row">',
'<div class="large-3 medium-3 small-3 columns">',
'<img src="'+obj.thumbnail_url+'" />',
'</div>',
'<div class="large-9 medium-9 small-9 columns">',
'<h4>'+obj.title+'</h4>',
'<p>'+obj.description+'</p>',
'</div>',
'</div>',
'<div class="iframe">'+obj.html+'</div>',
'</div>',
'</li>'].join(' '));
});
// grab the iframes and create players from them.
$('.track iframe').each(function(i, e){
var player = new playerjs.Player(e);
players.push(player);
player.on('ready', function(){
player.unmute();
onReady();
});
});
});
});
})(jQuery, document, window);