This repository has been archived by the owner on Aug 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
meteor-music-player.js
91 lines (76 loc) · 2.22 KB
/
meteor-music-player.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
84
85
86
87
88
89
90
91
if (Meteor.isClient) {
youtubeBackend = new MusicPlayer.backends.youtube({
});
soundcloudBackend = new MusicPlayer.backends.soundcloud({
}).init();
musicPlayer = new MusicPlayer({
backends: 'youtube',
});
Template.hello.events({
'click [data-action="load"]': function () {
var url = "/tracks/293"
soundcloudBackend.load(url);
},
});
Template.player.statusIs = function (str) {
var status = soundcloudBackend.status();
console.log('status', status);
return status == str;
};
Template.player.title = function () {
return soundcloudBackend.title();
};
Template.player.artwork_url = function () {
return soundcloudBackend.artwork_url();
};
var dragging = false;
Template.player.rendered = function () {
var el = this.find('.player-slider input[type="range"]');
el.addEventListener('input', function (e) {
dragging = true;
});
el.addEventListener('change', function (e) {
dragging = false;
soundcloudBackend.seekTo(this.value);
});
Deps.autorun(function () {
var pos = soundcloudBackend.getPosition();
if (!dragging)
el.value = pos;
});
Deps.autorun(function () {
var dur = soundcloudBackend.getDuration();
el.max = dur;
});
};
Template.player.duration = function () {
var duration = soundcloudBackend.getDuration();
duration = moment.duration(duration, 'ms');
var time = moment.utc(duration.asMilliseconds());
if (duration.asHours() >= 1) {
return time.format('HH:mm:ss');
} else {
return time.format('mm:ss');
}
};
Template.player.remaining = function () {
var duration = soundcloudBackend.getDuration() - soundcloudBackend.getPosition();
duration = moment.duration(duration, 'ms');
var time = moment.utc(duration.asMilliseconds());
if (duration.asHours() >= 1) {
return time.format('HH:mm:ss');
} else {
return time.format('mm:ss');
}
};
Template.player.events({
'click .player-pause': function () {
console.log('pause', soundcloudBackend.pause);
soundcloudBackend.pause();
},
'click .player-play': function () {
console.log('play');
soundcloudBackend.play();
},
});
}