Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. export default class VideoWithInterlock{
  2. constructor(video,reasons){
  3. this.video=video;
  4. this.reasons=reasons;
  5. this.reasons.push("user");
  6. this.interlocks={};
  7. for(let reason of this.reasons){
  8. this.interlocks[reason]=false;
  9. }
  10. this.interlocks["user"]=true;
  11.  
  12. }
  13. pause(reason="user"){
  14. this.onChangeLock(reason,true);
  15. }
  16. play(reason="user"){
  17. this.onChangeLock(reason,false);
  18. }
  19. get isAnyLock(){
  20. return this.reasons
  21. .map((reason)=>this.interlocks[reason])
  22. .reduce((a,b)=>a||b);
  23. }
  24. onChangeLock(reason,isLock){
  25. let previousIsAnyLock=this.isAnyLock;
  26. this.interlocks[reason]=isLock;
  27. let isAnyLock=this.isAnyLock;
  28. if(previousIsAnyLock!=isAnyLock){
  29. if(isAnyLock){
  30. this.video.pause();
  31. }else{
  32. this.video.play();
  33. }
  34. }
  35.  
  36. }
  37. get readyState(){
  38. return this.video.readyState;
  39. }
  40. get currentTime(){
  41. return this.video.currentTime;
  42. }
  43. set currentTime(currentTime){
  44. this.video.currentTime=currentTime;
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement