daily pastebin goal
2%
SHARE
TWEET

Untitled

a guest Mar 13th, 2018 46 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. export interface IMedia {
  2.    title: string;
  3.    src: string;
  4.    type: string;
  5.  
  6. }
  7.  
  8.  
  9. @Component({
  10.   selector: 'app-root',
  11.   templateUrl: './app.component.html',
  12.   styleUrls: ['./app.component.css']
  13. })
  14. export class AppComponent {
  15.     elem: any;
  16.     title = 'app works!';
  17.     isActive: boolean = false;
  18.     isCompleted: boolean = false;
  19.     isPlayerReady: boolean = false;
  20.     playlist:any;
  21.     state: string = VgStates.VG_PAUSED;
  22.  
  23.     constructor(private list: VideoListService) {
  24.  
  25.         this.list.fetchdata().subscribe((data)=>{   //Fetch json Data From Service
  26.             this.playlist=data;
  27.             console.log("Video Data",data);
  28.  
  29.        })
  30.  
  31.  
  32.     }
  33.  
  34.     ngOnInit(){
  35.       //this.playlist: Array<IMedia> = this.list.getPlaylist()
  36.     }
  37.  
  38.  
  39.     currentIndex = 0; //Can not a read a propert 0 undefind.
  40.     currentItem: IMedia = this.playlist[this.currentIndex ];
  41.     api: VgAPI;
  42.     latestV;
  43.  
  44.     toggle() {
  45.         this.isActive = !this.isActive;
  46.         console.log(this.isActive);
  47.         if(!this.isActive){
  48.             this.api.getDefaultMedia().subscriptions.ended.subscribe( this.prevVideo.bind(this) );
  49.         }else{
  50.             this.api.getDefaultMedia().subscriptions.ended.subscribe( this.nextVideo.bind(this) );
  51.         }
  52.     }
  53.  
  54.     onPlayerReady(api: VgAPI) {
  55.         //console.log(api);
  56.         this.api = api;
  57.         this.api.getDefaultMedia().subscriptions.loadedMetadata.subscribe(this.playVideo.bind(this));        
  58.     }
  59.  
  60.     nextVideo() {
  61.         this.currentIndex++;
  62.         if (this.currentIndex === this.playlist.length) {
  63.             this.currentIndex = 0;
  64.         }
  65.         this.currentItem = this.playlist[ this.currentIndex ];
  66.     }    
  67.  
  68.     prevVideo() {
  69.         this.currentIndex--;
  70.         if (this.currentIndex === this.playlist.length) {
  71.             this.currentIndex = 0;
  72.         }
  73.         this.currentItem = this.playlist[ this.currentIndex ];
  74.         setTimeout(function() {
  75.             this.api.pause();
  76.         }.bind(this),100);
  77.     }
  78.  
  79.     playVideo() {
  80.         this.api.play();
  81.     }
  82.  
  83.     onClickPlaylistItem(item: IMedia) {
  84.         console.log(item);
  85.         this.currentItem = item;
  86.     };
  87.  
  88.     onClickPlayPrevItem() {
  89.         this.currentIndex-=1;
  90.         this.currentItem = this.playlist[ this.currentIndex ];
  91.         console.log(this.currentIndex);
  92.     };
  93.  
  94.     onClickPlayNextItem() {
  95.         this.currentIndex+=1;
  96.         this.currentItem = this.playlist[ this.currentIndex];
  97.         console.log(this.currentIndex);
  98.     };
  99.  
  100.  
  101. }
  102.    
  103. import { Injectable } from '@angular/core';
  104. import { Http, Response } from "@angular/http";
  105. import { Observable } from "rxjs/Observable";
  106. import "rxjs/Rx";
  107. @Injectable()
  108. export class VideoListService {
  109.  
  110.     constructor(private http: Http) { }
  111.  
  112.  
  113.     fetchdata() {
  114.         return this.http.get("../assets/data/video/video_list.json");
  115.     }
  116.  
  117. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top