author | Chloe Laisne <chloe.laisne@gmail.com> |
Wed, 29 Jun 2016 00:35:03 +0200 | |
changeset 212 | f2c6080a73aa |
parent 211 | 7451203a1321 |
child 214 | 9bff007eb03c |
permissions | -rw-r--r-- |
86
15ded106ef1a
add a player component to handle sound play/pause
nowmad@23.1.168.192.in-addr.arpa
parents:
diff
changeset
|
1 |
import Ember from 'ember'; |
15ded106ef1a
add a player component to handle sound play/pause
nowmad@23.1.168.192.in-addr.arpa
parents:
diff
changeset
|
2 |
|
15ded106ef1a
add a player component to handle sound play/pause
nowmad@23.1.168.192.in-addr.arpa
parents:
diff
changeset
|
3 |
export default Ember.Component.extend({ |
191
db5711fbbb6c
Player component linting
Chloe Laisne <chloe.laisne@gmail.com>
parents:
94
diff
changeset
|
4 |
classNames: ['player-component'], |
209
35cb7200bb0a
Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents:
192
diff
changeset
|
5 |
|
35cb7200bb0a
Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents:
192
diff
changeset
|
6 |
player: Ember.inject.service(), |
211 | 7 |
playing: false, |
8 |
popcorn: null, |
|
209
35cb7200bb0a
Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents:
192
diff
changeset
|
9 |
|
211 | 10 |
head: 0, |
11 |
remaining: 0, |
|
86
15ded106ef1a
add a player component to handle sound play/pause
nowmad@23.1.168.192.in-addr.arpa
parents:
diff
changeset
|
12 |
|
212
f2c6080a73aa
Player backward/forward design logic
Chloe Laisne <chloe.laisne@gmail.com>
parents:
211
diff
changeset
|
13 |
isFirst: false, |
f2c6080a73aa
Player backward/forward design logic
Chloe Laisne <chloe.laisne@gmail.com>
parents:
211
diff
changeset
|
14 |
isLast: false, |
f2c6080a73aa
Player backward/forward design logic
Chloe Laisne <chloe.laisne@gmail.com>
parents:
211
diff
changeset
|
15 |
|
f2c6080a73aa
Player backward/forward design logic
Chloe Laisne <chloe.laisne@gmail.com>
parents:
211
diff
changeset
|
16 |
item: Ember.computed('player.model', function() { |
f2c6080a73aa
Player backward/forward design logic
Chloe Laisne <chloe.laisne@gmail.com>
parents:
211
diff
changeset
|
17 |
return this.get('player').get('model'); |
210 | 18 |
}), |
19 |
||
212
f2c6080a73aa
Player backward/forward design logic
Chloe Laisne <chloe.laisne@gmail.com>
parents:
211
diff
changeset
|
20 |
modelLoaded: Ember.observer('player.model', function() { |
f2c6080a73aa
Player backward/forward design logic
Chloe Laisne <chloe.laisne@gmail.com>
parents:
211
diff
changeset
|
21 |
var items = this.get('player').get('items'); |
f2c6080a73aa
Player backward/forward design logic
Chloe Laisne <chloe.laisne@gmail.com>
parents:
211
diff
changeset
|
22 |
var index = items.indexOf(this.get('player').get('item')); |
f2c6080a73aa
Player backward/forward design logic
Chloe Laisne <chloe.laisne@gmail.com>
parents:
211
diff
changeset
|
23 |
this.set('isFirst', index === 0); |
f2c6080a73aa
Player backward/forward design logic
Chloe Laisne <chloe.laisne@gmail.com>
parents:
211
diff
changeset
|
24 |
this.set('isLast', index === items.length - 1); |
191
db5711fbbb6c
Player component linting
Chloe Laisne <chloe.laisne@gmail.com>
parents:
94
diff
changeset
|
25 |
}), |
86
15ded106ef1a
add a player component to handle sound play/pause
nowmad@23.1.168.192.in-addr.arpa
parents:
diff
changeset
|
26 |
|
209
35cb7200bb0a
Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents:
192
diff
changeset
|
27 |
init: function() { |
35cb7200bb0a
Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents:
192
diff
changeset
|
28 |
this._super(...arguments); |
35cb7200bb0a
Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents:
192
diff
changeset
|
29 |
this.get('player'); |
35cb7200bb0a
Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents:
192
diff
changeset
|
30 |
}, |
35cb7200bb0a
Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents:
192
diff
changeset
|
31 |
|
191
db5711fbbb6c
Player component linting
Chloe Laisne <chloe.laisne@gmail.com>
parents:
94
diff
changeset
|
32 |
didInsertElement: function() { |
211 | 33 |
this.set('popcorn', Popcorn('#popcorn-audio')); |
34 |
this.get('popcorn').on('timeupdate', Ember.run.bind(this, this.get('onProgress'))); |
|
35 |
}, |
|
36 |
||
37 |
onProgress: function(event) { |
|
38 |
var currentTime = this.get('popcorn').currentTime(); |
|
39 |
var duration = this.get('popcorn').duration(); |
|
40 |
this.$('.bar .value').width(currentTime * 100 / duration + '%'); |
|
41 |
this.set('head', currentTime); |
|
42 |
this.set('remaining', duration - currentTime); |
|
87
24fef043ea0b
add control to go next/previous sound
nowmad@nowmads-macbook-pro.local
parents:
86
diff
changeset
|
43 |
}, |
191
db5711fbbb6c
Player component linting
Chloe Laisne <chloe.laisne@gmail.com>
parents:
94
diff
changeset
|
44 |
|
db5711fbbb6c
Player component linting
Chloe Laisne <chloe.laisne@gmail.com>
parents:
94
diff
changeset
|
45 |
actions: { |
db5711fbbb6c
Player component linting
Chloe Laisne <chloe.laisne@gmail.com>
parents:
94
diff
changeset
|
46 |
|
210 | 47 |
play: function() { |
211 | 48 |
if(this.get('playing')) { |
49 |
this.get('popcorn').pause(); |
|
50 |
} else { |
|
51 |
this.get('popcorn').play(); |
|
52 |
} |
|
53 |
this.set('playing', !this.get('playing')); |
|
212
f2c6080a73aa
Player backward/forward design logic
Chloe Laisne <chloe.laisne@gmail.com>
parents:
211
diff
changeset
|
54 |
}, |
f2c6080a73aa
Player backward/forward design logic
Chloe Laisne <chloe.laisne@gmail.com>
parents:
211
diff
changeset
|
55 |
|
f2c6080a73aa
Player backward/forward design logic
Chloe Laisne <chloe.laisne@gmail.com>
parents:
211
diff
changeset
|
56 |
backward: function() { |
f2c6080a73aa
Player backward/forward design logic
Chloe Laisne <chloe.laisne@gmail.com>
parents:
211
diff
changeset
|
57 |
console.log('backward'); |
f2c6080a73aa
Player backward/forward design logic
Chloe Laisne <chloe.laisne@gmail.com>
parents:
211
diff
changeset
|
58 |
}, |
f2c6080a73aa
Player backward/forward design logic
Chloe Laisne <chloe.laisne@gmail.com>
parents:
211
diff
changeset
|
59 |
|
f2c6080a73aa
Player backward/forward design logic
Chloe Laisne <chloe.laisne@gmail.com>
parents:
211
diff
changeset
|
60 |
forward: function() { |
f2c6080a73aa
Player backward/forward design logic
Chloe Laisne <chloe.laisne@gmail.com>
parents:
211
diff
changeset
|
61 |
console.log('forward'); |
191
db5711fbbb6c
Player component linting
Chloe Laisne <chloe.laisne@gmail.com>
parents:
94
diff
changeset
|
62 |
} |
db5711fbbb6c
Player component linting
Chloe Laisne <chloe.laisne@gmail.com>
parents:
94
diff
changeset
|
63 |
|
86
15ded106ef1a
add a player component to handle sound play/pause
nowmad@23.1.168.192.in-addr.arpa
parents:
diff
changeset
|
64 |
} |
15ded106ef1a
add a player component to handle sound play/pause
nowmad@23.1.168.192.in-addr.arpa
parents:
diff
changeset
|
65 |
}); |