cms/app-client/app/services/player.js
author Chloe Laisne <chloe.laisne@gmail.com>
Sun, 02 Oct 2016 15:24:56 +0200
changeset 311 f4327199e8f0
parent 271 e234339fe8df
child 338 4a3899b6a7ed
permissions -rw-r--r--
Solve count value on discourses

import Ember from 'ember';

export default Ember.Service.extend(Ember.Evented, {

    items: [],
    item: null,
    model: null,
    transcript: null,

    window: false,
    playing: false,
    progress: 0, // In Milliseconds
    videoscreen: false,

    modelObserver: Ember.observer('model', function() {
        this.toggleVideoscreen(this.get('model').get('video'));
    }),

    displayAdditionalInformation: function(el) {
        if(el === 'video') {
            this.toggleVideoscreen();
        } else {
            this.displayMetadata(el);
        }
    },

    displayMetadata: function(el) {
         if(this.get('window') !== el) {
            this.set('window', el);
        } else {
            this.set('window', false);
        }
    },

    toggleVideoscreen: function(state) {
        if(typeof state === 'undefined') {
            this.set('videoscreen', !this.get('videoscreen'));
        } else {
            this.set('videoscreen', state);
        }        
    },

    init: function() {
        this.on('reset', Ember.run.bind(this, this.get('reset')));
    },

    setProgress: function(time) {
        this.set('progress', time);
    },

    select: function (id) {
        this.set('item', id);
    },

    play: function(id) {
        this.select(id);
        this.set('playing', true);
    },

    pause: function() {
        this.set('playing', false);
    },

    reset: function(id) {
        this.set('item', id);
    }
});