-
Notifications
You must be signed in to change notification settings - Fork 0
/
paper-player.js
78 lines (75 loc) · 1.87 KB
/
paper-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
(function () {
'use strict'
Polymer({
ready: function() {
this.tracks = [
{
title: 'Linus Young - Home',
src: 'http://cs7-4v4.vk.me/p18/6102920be909b4.mp3'
},
{
title: 'Linus Young - Crystal Ball',
src: 'http://cs7-3v4.vk.me/p18/33a06f5f4a8fe9.mp3'
}
]
this.player = this.$.playerContainer
this.current = this.tracks[0]
this.played = !this.player.paused
},
setTrack: function(e, d, s) {
this.current = s.templateInstance.model.track
return this.play()
},
seekTo: function(e, d, s) {
this.player.currentTime = s.value
},
togglePlay: function() {
this.played ? this.pause() : this.play()
},
trackEnded: function() {
var pos = this.tracks.indexOf(this.current) + 1
pos = this.tracks[pos] ? pos : 0
this.current = this.tracks[pos]
this.play()
},
durationChange: function() {
this.trackDuration = this.player.duration
},
timeUpdate: function() {
this.currentTrackDurration = this.player.currentTime
},
progressUpdate: function() {
var buf = this.player.buffered,
len = buf.length
if (len) {
this.downloaded = buf.end(len - 1)
}
},
toTime: function(val) {
var m = Math.round(val / 60),
s = Math.round(val % 60)
if (s < 10) s = '0' + s
return [m, s].join(':')
},
printJson: {
toDOM: function(value) {
return value && JSON.stringify(value, null, '\t')
},
toModel: function(value) {
return value && JSON.parse(value)
}
},
play: function() {
this.async(function() {
this.player.play()
})
this.played = true
return this
},
pause: function() {
this.player.pause()
this.played = false
return this
}
})
})()