src/widgets/AutoPlayer.js
author ymh <ymh.work@gmail.com>
Tue, 22 Oct 2024 09:54:34 +0200
changeset 1080 2b513bcb710a
parent 1078 c28fb800e252
permissions -rw-r--r--
increment version
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: 1071
diff changeset
     1
// AutoPlayer
959
ee11ed1b739e Mashup Player and Dailymotion are now widgets
veltr
parents:
diff changeset
     2
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
     3
const AutoPlayer = function (ns) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
     4
  return class extends ns.Widgets.Widget {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
     5
    constructor(player, config) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
     6
      super(player, config);
959
ee11ed1b739e Mashup Player and Dailymotion are now widgets
veltr
parents:
diff changeset
     7
    }
1071
02c04d2c8fd8 Various changes from git version and make autoplayer determine video type on lowercase url
ymh <ymh.work@gmail.com>
parents: 1042
diff changeset
     8
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
     9
    static defaults = {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    10
      default_type: "HtmlPlayer",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    11
    };
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    12
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    13
    draw() {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    14
      if (typeof this.video === "undefined") {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    15
        this.video = this.media.video;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    16
      }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    17
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    18
      var _props = [
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    19
          "live",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    20
          "provider",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    21
          "autostart",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    22
          "streamer",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    23
          "video",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    24
          "height",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    25
          "width",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    26
          "url_transform",
1078
c28fb800e252 VideojsPlayer for Dailymotion in AutoPlayer
ymh <ymh.work@gmail.com>
parents: 1073
diff changeset
    27
          "dailymotionPlayerId"
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    28
        ],
959
ee11ed1b739e Mashup Player and Dailymotion are now widgets
veltr
parents:
diff changeset
    29
        _opts = {},
ee11ed1b739e Mashup Player and Dailymotion are now widgets
veltr
parents:
diff changeset
    30
        _types = [
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    31
          {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    32
            regexp: /\.(mp4|m4v|mp3)$/,
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    33
            type: "AdaptivePlayer",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    34
          },
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    35
          {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    36
            regexp: /\.(ogg|ogv|webm)$/,
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    37
            type: "HtmlPlayer",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    38
          },
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    39
          {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    40
            regexp: /^(https?:\/\/)?(www\.)?youtube\.com/,
1073
687133dc13cf Add VideojsPlayer for handling youtube and vimeo
ymh <ymh.work@gmail.com>
parents: 1072
diff changeset
    41
            type: "VideojsPlayer",
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    42
          },
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    43
          {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    44
            regexp: /^(https?:\/\/)?(www\.)?vimeo\.com/,
1073
687133dc13cf Add VideojsPlayer for handling youtube and vimeo
ymh <ymh.work@gmail.com>
parents: 1072
diff changeset
    45
            type: "VideojsPlayer",
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    46
          },
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    47
          {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    48
            regexp: /^(https?:\/\/)?(www\.)?dailymotion\.com/,
1078
c28fb800e252 VideojsPlayer for Dailymotion in AutoPlayer
ymh <ymh.work@gmail.com>
parents: 1073
diff changeset
    49
            type: "VideojsPlayer",
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    50
          },
1073
687133dc13cf Add VideojsPlayer for handling youtube and vimeo
ymh <ymh.work@gmail.com>
parents: 1072
diff changeset
    51
        ]
1071
02c04d2c8fd8 Various changes from git version and make autoplayer determine video type on lowercase url
ymh <ymh.work@gmail.com>
parents: 1042
diff changeset
    52
1073
687133dc13cf Add VideojsPlayer for handling youtube and vimeo
ymh <ymh.work@gmail.com>
parents: 1072
diff changeset
    53
      if(this.video) {
687133dc13cf Add VideojsPlayer for handling youtube and vimeo
ymh <ymh.work@gmail.com>
parents: 1072
diff changeset
    54
        for (var i = 0; i < _types.length; i++) {
687133dc13cf Add VideojsPlayer for handling youtube and vimeo
ymh <ymh.work@gmail.com>
parents: 1072
diff changeset
    55
          if (_types[i].regexp.test(this.video.toLowerCase())) {
687133dc13cf Add VideojsPlayer for handling youtube and vimeo
ymh <ymh.work@gmail.com>
parents: 1072
diff changeset
    56
            _opts.type = _types[i].type;
687133dc13cf Add VideojsPlayer for handling youtube and vimeo
ymh <ymh.work@gmail.com>
parents: 1072
diff changeset
    57
            break;
687133dc13cf Add VideojsPlayer for handling youtube and vimeo
ymh <ymh.work@gmail.com>
parents: 1072
diff changeset
    58
          }
959
ee11ed1b739e Mashup Player and Dailymotion are now widgets
veltr
parents:
diff changeset
    59
        }
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    60
      }
1071
02c04d2c8fd8 Various changes from git version and make autoplayer determine video type on lowercase url
ymh <ymh.work@gmail.com>
parents: 1042
diff changeset
    61
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    62
      if (typeof _opts.type === "undefined") {
1013
392ddcd212d7 Throwed in a bunch of semicolons
veltr
parents: 987
diff changeset
    63
        _opts.type = this.default_type;
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    64
      }
1071
02c04d2c8fd8 Various changes from git version and make autoplayer determine video type on lowercase url
ymh <ymh.work@gmail.com>
parents: 1042
diff changeset
    65
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    66
      if (_opts.type === "AdaptivePlayer") {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    67
        var _canPlayType = document
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    68
          .createElement("video")
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    69
          .canPlayType('video/mp4; codecs="avc1.42E01E"');
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    70
        _opts.type = _canPlayType !== "no" ? "HtmlPlayer" : "JwpPlayer";
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    71
      }
1071
02c04d2c8fd8 Various changes from git version and make autoplayer determine video type on lowercase url
ymh <ymh.work@gmail.com>
parents: 1042
diff changeset
    72
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    73
      for (var i = 0; i < _props.length; i++) {
959
ee11ed1b739e Mashup Player and Dailymotion are now widgets
veltr
parents:
diff changeset
    74
        if (typeof this[_props[i]] !== "undefined") {
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    75
          _opts[_props[i]] = this[_props[i]];
959
ee11ed1b739e Mashup Player and Dailymotion are now widgets
veltr
parents:
diff changeset
    76
        }
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    77
      }
959
ee11ed1b739e Mashup Player and Dailymotion are now widgets
veltr
parents:
diff changeset
    78
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    79
      this.insertSubwidget(this.$, _opts);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    80
    };
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    81
  };
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    82
};
1071
02c04d2c8fd8 Various changes from git version and make autoplayer determine video type on lowercase url
ymh <ymh.work@gmail.com>
parents: 1042
diff changeset
    83
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    84
export { AutoPlayer };