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