all files / buffering/ vg-buffering.ts

76.67% Statements 23/30
0% Branches 0/2
44.44% Functions 4/9
77.78% Lines 21/27
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167                                                                                                                                                                                                                                                                                                    
import { Component, ElementRef, HostBinding, Input, OnDestroy, OnInit, ViewEncapsulation } from '@angular/core';
import { VgAPI } from '../core/services/vg-api';
import { IPlayable } from '../core/vg-media/i-playable';
import { VgStates } from '../core/states/vg-states';
import { Subscription } from 'rxjs/Subscription';
 
 
export class VgBuffering implements OnInit, OnDestroy {
     vgFor: string;
 
    elem: HTMLElement;
    target: IPlayable;
    checkInterval: number = 50;
    currentPlayPos: number = 0;
    lastPlayPos: number = 0;
 
    subscriptions: Subscription[] = [];
 
     isBuffering: boolean = false;
 
    constructor(ref: ElementRef, public API: VgAPI) {
        this.elem = ref.nativeElement;
    }
 
    ngOnInit() {
        if (this.API.isPlayerReady) {
            this.onPlayerReady();
        }
        else {
            this.subscriptions.push(
                this.API.playerReadyEvent.subscribe(() => this.onPlayerReady())
            );
        }
    }
 
    onPlayerReady() {
        this.target = this.API.getMediaById(this.vgFor);
 
        this.subscriptions.push(
            this.target.subscriptions.bufferDetected.subscribe(
                isBuffering => this.onUpdateBuffer(isBuffering)
            )
        );
    }
 
    onUpdateBuffer(isBuffering) {
        this.isBuffering = isBuffering;
    }
 
    ngOnDestroy() {
        this.subscriptions.forEach(s => s.unsubscribe());
    }
static decorators: DecoratorInvocation[] = [
{ type: Component, args: [{
    selector: 'vg-buffering',
    encapsulation: ViewEncapsulation.None,
    template: `<div class="vg-buffering">
            <div class="bufferingContainer">
                <div class="loadingSpinner"></div>
            </div>
        </div>`,
    styles: [ `
        vg-buffering {
            display: none;
            z-index: 201;
        }
 
        vg-buffering.is-buffering {
            display: block;
        }
        
        .vg-buffering {
            position: absolute;
            display: block;
            width: 100%;
            height: 100%;
        }
 
        .vg-buffering .bufferingContainer {
            width: 100%;
            position: absolute;
            cursor: pointer;
            top: 50%;
            margin-top: -50px;
 
            zoom: 1;
            filter: alpha(opacity=60);
            opacity: 0.6;
        }
 
        /* Loading Spinner
        * http://www.alessioatzeni.com/blog/css3-loading-animation-loop/
        */
        .vg-buffering .loadingSpinner {
            background-color: rgba(0, 0, 0, 0);
            border: 5px solid rgba(255, 255, 255, 1);
            opacity: .9;
            border-top: 5px solid rgba(0, 0, 0, 0);
            border-left: 5px solid rgba(0, 0, 0, 0);
            border-radius: 50px;
            box-shadow: 0 0 35px #FFFFFF;
            width: 50px;
            height: 50px;
            margin: 0 auto;
            -moz-animation: spin .5s infinite linear;
            -webkit-animation: spin .5s infinite linear;
        }
 
        .vg-buffering .loadingSpinner .stop {
            -webkit-animation-play-state: paused;
            -moz-animation-play-state: paused;
        }
 
        @-moz-keyframes spin {
            0% {
                -moz-transform: rotate(0deg);
            }
            100% {
                -moz-transform: rotate(360deg);
            }
        }
 
        @-moz-keyframes spinoff {
            0% {
                -moz-transform: rotate(0deg);
            }
            100% {
                -moz-transform: rotate(-360deg);
            }
        }
 
        @-webkit-keyframes spin {
            0% {
                -webkit-transform: rotate(0deg);
            }
            100% {
                -webkit-transform: rotate(360deg);
            }
        }
 
        @-webkit-keyframes spinoff {
            0% {
                -webkit-transform: rotate(0deg);
            }
            100% {
                -webkit-transform: rotate(-360deg);
            }
        }
    ` ]
}, ] },
];
/** @nocollapse */
static ctorParameters: ({type: any, decorators?: DecoratorInvocation[]}|null)[] = [
{type: ElementRef, },
{type: VgAPI, },
];
static propDecorators: {[key: string]: DecoratorInvocation[]} = {
'vgFor': [{ type: Input },],
'isBuffering': [{ type: HostBinding, args: ['class.is-buffering', ] },],
};
}
 
interface DecoratorInvocation {
  type: Function;
  args?: any[];
}