author | Chloe Laisne <chloe.laisne@gmail.com> |
Tue, 28 Jun 2016 23:36:40 +0200 | |
changeset 211 | 7451203a1321 |
parent 210 | 08ad36c693b1 |
child 212 | f2c6080a73aa |
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 |
|
210 | 13 |
item: Ember.computed('player.item', function() { |
14 |
return this.get('player').get('item'); |
|
15 |
}), |
|
16 |
||
209
35cb7200bb0a
Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents:
192
diff
changeset
|
17 |
documentLoaded: Ember.observer('player.item', function() { |
191
db5711fbbb6c
Player component linting
Chloe Laisne <chloe.laisne@gmail.com>
parents:
94
diff
changeset
|
18 |
}), |
86
15ded106ef1a
add a player component to handle sound play/pause
nowmad@23.1.168.192.in-addr.arpa
parents:
diff
changeset
|
19 |
|
209
35cb7200bb0a
Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents:
192
diff
changeset
|
20 |
init: function() { |
35cb7200bb0a
Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents:
192
diff
changeset
|
21 |
this._super(...arguments); |
35cb7200bb0a
Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents:
192
diff
changeset
|
22 |
this.get('player'); |
35cb7200bb0a
Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents:
192
diff
changeset
|
23 |
}, |
35cb7200bb0a
Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents:
192
diff
changeset
|
24 |
|
191
db5711fbbb6c
Player component linting
Chloe Laisne <chloe.laisne@gmail.com>
parents:
94
diff
changeset
|
25 |
didInsertElement: function() { |
211 | 26 |
this.set('popcorn', Popcorn('#popcorn-audio')); |
27 |
this.get('popcorn').on('timeupdate', Ember.run.bind(this, this.get('onProgress'))); |
|
28 |
}, |
|
29 |
||
30 |
onProgress: function(event) { |
|
31 |
var currentTime = this.get('popcorn').currentTime(); |
|
32 |
var duration = this.get('popcorn').duration(); |
|
33 |
this.$('.bar .value').width(currentTime * 100 / duration + '%'); |
|
34 |
this.set('head', currentTime); |
|
35 |
this.set('remaining', duration - currentTime); |
|
87
24fef043ea0b
add control to go next/previous sound
nowmad@nowmads-macbook-pro.local
parents:
86
diff
changeset
|
36 |
}, |
191
db5711fbbb6c
Player component linting
Chloe Laisne <chloe.laisne@gmail.com>
parents:
94
diff
changeset
|
37 |
|
db5711fbbb6c
Player component linting
Chloe Laisne <chloe.laisne@gmail.com>
parents:
94
diff
changeset
|
38 |
actions: { |
db5711fbbb6c
Player component linting
Chloe Laisne <chloe.laisne@gmail.com>
parents:
94
diff
changeset
|
39 |
|
210 | 40 |
play: function() { |
211 | 41 |
if(this.get('playing')) { |
42 |
this.get('popcorn').pause(); |
|
43 |
} else { |
|
44 |
this.get('popcorn').play(); |
|
45 |
} |
|
46 |
this.set('playing', !this.get('playing')); |
|
191
db5711fbbb6c
Player component linting
Chloe Laisne <chloe.laisne@gmail.com>
parents:
94
diff
changeset
|
47 |
} |
db5711fbbb6c
Player component linting
Chloe Laisne <chloe.laisne@gmail.com>
parents:
94
diff
changeset
|
48 |
|
86
15ded106ef1a
add a player component to handle sound play/pause
nowmad@23.1.168.192.in-addr.arpa
parents:
diff
changeset
|
49 |
} |
15ded106ef1a
add a player component to handle sound play/pause
nowmad@23.1.168.192.in-addr.arpa
parents:
diff
changeset
|
50 |
}); |