cms/app-client/app/components/player-component.js
changeset 248 256272c33349
parent 247 7a5d729992b8
child 249 e4204b1a579a
equal deleted inserted replaced
247:7a5d729992b8 248:256272c33349
    35 
    35 
    36     progressObserver: Ember.observer('player.progress', function() {
    36     progressObserver: Ember.observer('player.progress', function() {
    37         this.get('popcorn').currentTime(this.get('player').get('progress') / 1000);
    37         this.get('popcorn').currentTime(this.get('player').get('progress') / 1000);
    38     }),
    38     }),
    39 
    39 
       
    40     playingObserver: Ember.observer('player.playing', function() {
       
    41         if(this.get('player').get('playing')) {
       
    42             this.play();
       
    43         } else {
       
    44             this.pause();
       
    45         } 
       
    46     }),
       
    47 
    40     init: function() {
    48     init: function() {
    41         this._super(...arguments);
    49         this._super(...arguments);
    42         this.get('player');
    50         this.get('player');
    43     },
    51     },
    44 
    52 
    45     didInsertElement: function() {
    53     didInsertElement: function() {
    46         this.set('popcorn', Popcorn('#popcorn-audio'));
    54         this.set('popcorn', Popcorn('#popcorn-audio'));
    47         this.get('popcorn').on('loadeddata', Ember.run.bind(this, this.get('onUpdate')));
    55         this.get('popcorn').on('loadeddata', Ember.run.bind(this, this.get('onUpdate')));
    48         this.get('popcorn').on('timeupdate', Ember.run.bind(this, this.get('onUpdate')));
    56         this.get('popcorn').on('timeupdate', Ember.run.bind(this, this.get('onUpdate')));
    49         this.get('popcorn').on('play', Ember.run.bind(this, this.get('onPlay')));
       
    50         this.get('popcorn').on('pause', Ember.run.bind(this, this.get('onPause')));
       
    51 
    57 
    52         this.get('player').on('reset', Ember.run.bind(this, function(id) {
    58         this.get('player').on('reset', Ember.run.bind(this, function(id) {
    53             if(this.get('player').get('item') !== id) {
    59             if(this.get('player').get('item') !== id) {
    54                 this.get('popcorn').on('loadeddata', Ember.run.bind(this, this.get('play')));
    60                 this.get('popcorn').on('loadeddata', Ember.run.bind(this, this.get('play')));
    55             } else {
    61             } else {
    65         this.get('player').set('progress', progress * 1000);
    71         this.get('player').set('progress', progress * 1000);
    66         this.set('head', progress);
    72         this.set('head', progress);
    67         this.set('remaining', duration - progress);
    73         this.set('remaining', duration - progress);
    68     },
    74     },
    69 
    75 
    70     onPlay: function() {
       
    71         this.get('player').set('playing', true);
       
    72     },
       
    73 
       
    74     onPause: function() {
       
    75         this.get('player').set('playing', false);
       
    76     },
       
    77 
       
    78     play: function() {
    76     play: function() {
    79         this.get('popcorn').play();
    77         this.get('popcorn').play();
    80     },
    78     },
    81 
    79 
    82     pause: function() {
    80     pause: function() {
    84     },
    82     },
    85 
    83 
    86     actions: {
    84     actions: {
    87 
    85 
    88         toggle: function() {
    86         toggle: function() {
    89             if(this.get('player').get('playing')) {
    87             this.get('player').set('playing', !this.get('player').get('playing'));
    90                 this.pause();
       
    91             } else {
       
    92                 this.play();
       
    93             } 
       
    94         },
    88         },
    95 
    89 
    96         backward: function() {
    90         backward: function() {
    97             var index = this.get('player').get('items').indexOf(this.get('player').get('item'));
    91             var index = this.get('player').get('items').indexOf(this.get('player').get('item'));
    98             var item = this.get('player').get('items')[index - 1];
    92             var item = this.get('player').get('items')[index - 1];