Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export default class VideoWithInterlock{
- constructor(video,reasons){
- this.video=video;
- this.reasons=reasons;
- this.reasons.push("user");
- this.interlocks={};
- for(let reason of this.reasons){
- this.interlocks[reason]=false;
- }
- this.interlocks["user"]=true;
- }
- pause(reason="user"){
- this.onChangeLock(reason,true);
- }
- play(reason="user"){
- this.onChangeLock(reason,false);
- }
- get isAnyLock(){
- return this.reasons
- .map((reason)=>this.interlocks[reason])
- .reduce((a,b)=>a||b);
- }
- onChangeLock(reason,isLock){
- let previousIsAnyLock=this.isAnyLock;
- this.interlocks[reason]=isLock;
- let isAnyLock=this.isAnyLock;
- if(previousIsAnyLock!=isAnyLock){
- if(isAnyLock){
- this.video.pause();
- }else{
- this.video.play();
- }
- }
- }
- get readyState(){
- return this.video.readyState;
- }
- get currentTime(){
- return this.video.currentTime;
- }
- set currentTime(currentTime){
- this.video.currentTime=currentTime;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement