import { Component, OnInit } from '@angular/core';
import { DomSanitizer} from '@angular/platform-browser';
import { BsModalService, ModalOptions, BsModalRef } from 'ngx-bootstrap/modal';
import { ExamVideoStdScoreComponent } from '../exam-video-std-score/exam-video-std-score.component';
import { AjaxService } from '../../../../../core/service/ajax.service';
import { FramePageComponent } from '../../../../frame/core/page/frame.page';
import { FrameDetailComponent } from '../../../../frame/core/detail/frame.detail';

declare var aliPlayerUtil :any;

@Component({
  selector: 'app-exam-video-room-std',
  templateUrl: './exam-video-room-std.component.html',
  styleUrls: ['./exam-video-room-std.component.scss']
})
export class ExamVideoRoomStdComponent extends FrameDetailComponent   implements OnInit {
  bsModalWin: any;
  VideoTotal: any;
  aliPlayer: any;
  tpl: any;
  constructor(bsModalRef: BsModalRef, sanitizer: DomSanitizer,private modalService: BsModalService) { 
    super(bsModalRef, sanitizer);
  }

  ngOnInit() {
  }

  startVideo(tpl, video_file) {
    this.tpl = tpl;
    this.nextGroupVideo(true, video_file);
  }

  nextGroupVideo(firstLoad, video_file) {
    if (firstLoad) {
      this.initVideoPlayer();
    }
    aliPlayerUtil.changeSource(this.aliPlayer, video_file);
  }

  initVideoPlayer(url?) {
    let _this = this;
    this.bsModalWin = this.modalService.show(this.tpl, { class: 'modal-9p' , backdrop: 'static', keyboard: false});
    this.aliPlayer = aliPlayerUtil.init('aliPlayer', url);
    // 技术播放自动下一个
    this.aliPlayer.on("ended", function() {
      debugger;
    });
  }

  changeVideoSource(url){
    aliPlayerUtil.changeSource(this.aliPlayer,url);
  }

  hideModal(){
    if(this.bsModalWin) this.bsModalWin.hide();
  }

  pauseVideo(){
    aliPlayerUtil.pause(this.aliPlayer);
  }

  playVideo(){
    aliPlayerUtil.play(this.aliPlayer);
  }
}
