cms/app-client/app/components/player-component.js
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--
Setup progress bar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
7451203a1321 Setup progress bar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 210
diff changeset
     7
    playing: false,
7451203a1321 Setup progress bar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 210
diff changeset
     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
7451203a1321 Setup progress bar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 210
diff changeset
    10
    head: 0,
7451203a1321 Setup progress bar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 210
diff changeset
    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
08ad36c693b1 Player design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 209
diff changeset
    13
    item: Ember.computed('player.item', function() {
08ad36c693b1 Player design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 209
diff changeset
    14
        return this.get('player').get('item');
08ad36c693b1 Player design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 209
diff changeset
    15
    }),
08ad36c693b1 Player design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 209
diff changeset
    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
7451203a1321 Setup progress bar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 210
diff changeset
    26
        this.set('popcorn', Popcorn('#popcorn-audio'));
7451203a1321 Setup progress bar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 210
diff changeset
    27
        this.get('popcorn').on('timeupdate', Ember.run.bind(this, this.get('onProgress')));
7451203a1321 Setup progress bar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 210
diff changeset
    28
    },
7451203a1321 Setup progress bar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 210
diff changeset
    29
7451203a1321 Setup progress bar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 210
diff changeset
    30
    onProgress: function(event) {
7451203a1321 Setup progress bar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 210
diff changeset
    31
        var currentTime = this.get('popcorn').currentTime();
7451203a1321 Setup progress bar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 210
diff changeset
    32
        var duration = this.get('popcorn').duration();
7451203a1321 Setup progress bar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 210
diff changeset
    33
        this.$('.bar .value').width(currentTime * 100 / duration + '%');
7451203a1321 Setup progress bar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 210
diff changeset
    34
        this.set('head', currentTime);
7451203a1321 Setup progress bar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 210
diff changeset
    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
08ad36c693b1 Player design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 209
diff changeset
    40
        play: function() {
211
7451203a1321 Setup progress bar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 210
diff changeset
    41
            if(this.get('playing')) {
7451203a1321 Setup progress bar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 210
diff changeset
    42
                this.get('popcorn').pause();
7451203a1321 Setup progress bar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 210
diff changeset
    43
            } else {
7451203a1321 Setup progress bar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 210
diff changeset
    44
                this.get('popcorn').play();
7451203a1321 Setup progress bar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 210
diff changeset
    45
            }
7451203a1321 Setup progress bar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 210
diff changeset
    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
});