summaryrefslogtreecommitdiff
path: root/public/js/lib/video.js
blob: aa01d237eae9f38ca38c41574400a92599ca8bf4 (plain)
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
var VideoView = View.extend({

  events: {
  },

  initialize: function(media){
    this.media = media
    this.mx
    this.build(media)
  },

  build: function(media){
    var mxType
    switch (media.type) {
      case 'video':
        mxType = MX.Video
        break
      case 'vimeo':
        mxType = MX.Vimeo
        break
      case 'youtube':
        mxType = MX.Youtube
        break
    }
    if (app.muted) {
      media.mute = true
    }
    this.mx = new mxType({
      media: media,
      backface: false,
    })
    this.el.innerHTML = ""
    this.el.appendChild(this.mx.el)
    
    this.mx.load()
  },
  
  play: function(){
    this.mx.play()
  },
  
  pause: function(){
    this.mx.pause()
  },
  
  toggle: function(shouldPause){
    if (typeof shouldPause !== "boolean") {
      shouldPause = ! this.mx.paused
    }
    shouldPause ? this.mx.pause() : this.mx.play()
    return shouldPause
  },
  
  toggleMuted: function(shouldMute){
    if (typeof shouldMute !== "boolean") {
      shouldMute = ! this.mx.muted
    }
    shouldMute ? this.mx.mute() : this.mx.unmute()
    return shouldMute
  },
  
  paused: function(){
    return this.mx.paused
  },
  
  muted: function(){
    return this.mx.muted
  },
  
  seek: function(n){
    this.mx.seek(n)
  },
  
  setLoop: function(shouldLoop){
    this.mx.setLoop(shouldLoop)
  },
  
  mute: function(muted){
    if (muted) {
      this.mx.mute()
    }
    else {
      this.mx.unmute()
    }
  },

  unmute: function(){
    this.mx.unmute()
  },
  
  setVolume: function(n){
    this.mx.setVolume(n)
  }

})