src/widgets/AutoPlayer.js
author ymh <ymh.work@gmail.com>
Thu, 17 Oct 2024 00:58:24 +0200
changeset 1073 687133dc13cf
parent 1072 ac1eacb3aa33
child 1078 c28fb800e252
permissions -rw-r--r--
Add VideojsPlayer for handling youtube and vimeo
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",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    27
        ],
959
ee11ed1b739e Mashup Player and Dailymotion are now widgets
veltr
parents:
diff changeset
    28
        _opts = {},
ee11ed1b739e Mashup Player and Dailymotion are now widgets
veltr
parents:
diff changeset
    29
        _types = [
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    30
          {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    31
            regexp: /\.(mp4|m4v|mp3)$/,
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    32
            type: "AdaptivePlayer",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    33
          },
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
            regexp: /\.(ogg|ogv|webm)$/,
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    36
            type: "HtmlPlayer",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    37
          },
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
            regexp: /^(https?:\/\/)?(www\.)?youtube\.com/,
1073
687133dc13cf Add VideojsPlayer for handling youtube and vimeo
ymh <ymh.work@gmail.com>
parents: 1072
diff changeset
    40
            type: "VideojsPlayer",
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    41
          },
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
            regexp: /^(https?:\/\/)?(www\.)?vimeo\.com/,
1073
687133dc13cf Add VideojsPlayer for handling youtube and vimeo
ymh <ymh.work@gmail.com>
parents: 1072
diff changeset
    44
            type: "VideojsPlayer",
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    45
          },
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
            regexp: /^(https?:\/\/)?(www\.)?dailymotion\.com/,
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    48
            type: "DailymotionPlayer",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    49
          },
1073
687133dc13cf Add VideojsPlayer for handling youtube and vimeo
ymh <ymh.work@gmail.com>
parents: 1072
diff changeset
    50
        ]
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
    51
1073
687133dc13cf Add VideojsPlayer for handling youtube and vimeo
ymh <ymh.work@gmail.com>
parents: 1072
diff changeset
    52
      if(this.video) {
687133dc13cf Add VideojsPlayer for handling youtube and vimeo
ymh <ymh.work@gmail.com>
parents: 1072
diff changeset
    53
        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
    54
          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
    55
            _opts.type = _types[i].type;
687133dc13cf Add VideojsPlayer for handling youtube and vimeo
ymh <ymh.work@gmail.com>
parents: 1072
diff changeset
    56
            break;
687133dc13cf Add VideojsPlayer for handling youtube and vimeo
ymh <ymh.work@gmail.com>
parents: 1072
diff changeset
    57
          }
959
ee11ed1b739e Mashup Player and Dailymotion are now widgets
veltr
parents:
diff changeset
    58
        }
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    59
      }
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
    60
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    61
      if (typeof _opts.type === "undefined") {
1013
392ddcd212d7 Throwed in a bunch of semicolons
veltr
parents: 987
diff changeset
    62
        _opts.type = this.default_type;
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    63
      }
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
    64
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    65
      if (_opts.type === "AdaptivePlayer") {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    66
        var _canPlayType = document
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    67
          .createElement("video")
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    68
          .canPlayType('video/mp4; codecs="avc1.42E01E"');
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    69
        _opts.type = _canPlayType !== "no" ? "HtmlPlayer" : "JwpPlayer";
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    70
      }
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
    71
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    72
      for (var i = 0; i < _props.length; i++) {
959
ee11ed1b739e Mashup Player and Dailymotion are now widgets
veltr
parents:
diff changeset
    73
        if (typeof this[_props[i]] !== "undefined") {
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    74
          _opts[_props[i]] = this[_props[i]];
959
ee11ed1b739e Mashup Player and Dailymotion are now widgets
veltr
parents:
diff changeset
    75
        }
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    76
      }
959
ee11ed1b739e Mashup Player and Dailymotion are now widgets
veltr
parents:
diff changeset
    77
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    78
      this.insertSubwidget(this.$, _opts);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    79
    };
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
};
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
    82
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    83
export { AutoPlayer };