src/widgets/AdaptivePlayer.js
author ymh <ymh.work@gmail.com>
Tue, 22 Oct 2024 07:03:54 +0200
changeset 1076 510fd2a482f4
parent 1073 687133dc13cf
permissions -rw-r--r--
Add Dailymotion Tech and remove unused libs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1042
diff changeset
     1
// Class AdaptivePlayer
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1042
diff changeset
     2
const AdaptivePlayer = function (ns) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1042
diff changeset
     3
  return class extends ns.Widgets.Widget {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1042
diff changeset
     4
    constructor(player, config) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1042
diff changeset
     5
      super(player, config);
967
b4c6e64acb2d Added a dual mode HTML/Flash player
veltr
parents:
diff changeset
     6
    }
b4c6e64acb2d Added a dual mode HTML/Flash player
veltr
parents:
diff changeset
     7
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1042
diff changeset
     8
    static defaults = {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1042
diff changeset
     9
      mime_type: 'video/mp4; codecs="avc1.42E01E"',
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1042
diff changeset
    10
      normal_player: "HtmlPlayer",
1073
687133dc13cf Add VideojsPlayer for handling youtube and vimeo
ymh <ymh.work@gmail.com>
parents: 1072
diff changeset
    11
      fallback_player: "VideojsPlayer",
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1042
diff changeset
    12
    };
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1042
diff changeset
    13
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1042
diff changeset
    14
    draw() {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1042
diff changeset
    15
      if (typeof this.video === "undefined") {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1042
diff changeset
    16
        this.video = this.media.video;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1042
diff changeset
    17
      }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1042
diff changeset
    18
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1042
diff changeset
    19
      var _props = ["autostart", "video", "height", "width", "url_transform"],
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1042
diff changeset
    20
        _opts = {},
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1042
diff changeset
    21
        _canPlayType = document
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1042
diff changeset
    22
          .createElement("video")
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1042
diff changeset
    23
          .canPlayType(this.mime_type);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1042
diff changeset
    24
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1042
diff changeset
    25
      _opts.type =
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1042
diff changeset
    26
        _canPlayType !== "no" ? this.normal_player : this.fallback_player;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1042
diff changeset
    27
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1042
diff changeset
    28
      for (var i = 0; i < _props.length; i++) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1042
diff changeset
    29
        if (typeof this[_props[i]] !== "undefined") {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1042
diff changeset
    30
          _opts[_props[i]] = this[_props[i]];
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1042
diff changeset
    31
        }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1042
diff changeset
    32
      }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1042
diff changeset
    33
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1042
diff changeset
    34
      this.insertSubwidget(this.$, _opts);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1042
diff changeset
    35
    }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1042
diff changeset
    36
  };
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1042
diff changeset
    37
};
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1042
diff changeset
    38
export { AdaptivePlayer };