src/widgets/AutoPlayer.js
changeset 1072 ac1eacb3aa33
parent 1071 02c04d2c8fd8
child 1073 687133dc13cf
equal deleted inserted replaced
1071:02c04d2c8fd8 1072:ac1eacb3aa33
     1 IriSP.Widgets.AutoPlayer = function(player, config) {
     1 // AutoPlayer
     2     IriSP.Widgets.Widget.call(this, player, config);
       
     3 };
       
     4 
     2 
     5 IriSP.Widgets.AutoPlayer.prototype = new IriSP.Widgets.Widget();
     3 const AutoPlayer = function (ns) {
     6 
     4   return class extends ns.Widgets.Widget {
     7 IriSP.Widgets.AutoPlayer.prototype.defaults = {
     5     constructor(player, config) {
     8     default_type: "JwpPlayer"
     6       super(player, config);
     9 };
       
    10 
       
    11 IriSP.Widgets.AutoPlayer.prototype.draw = function() {
       
    12 
       
    13     if (typeof this.video === "undefined") {
       
    14         this.video = this.media.video;
       
    15     }
     7     }
    16 
     8 
    17     var _props = [ "live", "provider", "autostart", "streamer", "video", "height", "width", "url_transform" ],
     9     static defaults = {
       
    10       default_type: "HtmlPlayer",
       
    11     };
       
    12 
       
    13     draw() {
       
    14       if (typeof this.video === "undefined") {
       
    15         this.video = this.media.video;
       
    16       }
       
    17 
       
    18       var _props = [
       
    19           "live",
       
    20           "provider",
       
    21           "autostart",
       
    22           "streamer",
       
    23           "video",
       
    24           "height",
       
    25           "width",
       
    26           "url_transform",
       
    27         ],
    18         _opts = {},
    28         _opts = {},
    19         _types = [
    29         _types = [
    20             {
    30           {
    21                 regexp: /^rtmp:\/\//,
    31             regexp: /^rtmp:\/\//,
    22                 type: "JwpPlayer"
    32             type: "JwpPlayer",
    23             },
    33           },
    24             {
    34           {
    25                 regexp: /\.(mp4|m4v|mp3)$/,
    35             regexp: /\.(mp4|m4v|mp3)$/,
    26                 type: "AdaptivePlayer"
    36             type: "AdaptivePlayer",
    27             },
    37           },
    28             {
    38           {
    29                 regexp: /\.(ogg|ogv|webm)$/,
    39             regexp: /\.(ogg|ogv|webm)$/,
    30                 type: "HtmlPlayer"
    40             type: "HtmlPlayer",
    31             },
    41           },
    32             {
    42           {
    33                 regexp: /^(https?:\/\/)?(www\.)?youtube\.com/,
    43             regexp: /^(https?:\/\/)?(www\.)?youtube\.com/,
    34                 type: "PopcornPlayer"
    44             type: "PopcornPlayer",
    35             },
    45           },
    36             {
    46           {
    37                 regexp: /^(https?:\/\/)?(www\.)?vimeo\.com/,
    47             regexp: /^(https?:\/\/)?(www\.)?vimeo\.com/,
    38                 type: "PopcornPlayer"
    48             type: "PopcornPlayer",
    39             },
    49           },
    40             {
    50           {
    41                 regexp: /^(https?:\/\/)?(www\.)?dailymotion\.com/,
    51             regexp: /^(https?:\/\/)?(www\.)?dailymotion\.com/,
    42                 type: "DailymotionPlayer"
    52             type: "DailymotionPlayer",
    43             }
    53           },
    44         ],
    54         ],
    45         _rtmprgx = /^rtmp:\/\//;
    55         _rtmprgx = /^rtmp:\/\//;
    46 
    56 
    47     for (var i = 0; i < _types.length; i++) {
    57       for (var i = 0; i < _types.length; i++) {
    48         if (this.video && _types[i].regexp.test(this.video.toLowerCase())) {
    58         if (this.video && _types[i].regexp.test(this.video.toLowerCase())) {
    49             _opts.type =  _types[i].type;
    59           _opts.type = _types[i].type;
    50             break;
    60           break;
    51         }
    61         }
    52     }
    62       }
    53 
    63 
    54     if (typeof _opts.type === "undefined") {
    64       if (typeof _opts.type === "undefined") {
    55         _opts.type = this.default_type;
    65         _opts.type = this.default_type;
    56     }
    66       }
    57 
    67 
    58     if (_opts.type === "AdaptivePlayer") {
    68       if (_opts.type === "AdaptivePlayer") {
    59         var _canPlayType = document.createElement('video').canPlayType('video/mp4; codecs="avc1.42E01E"');
    69         var _canPlayType = document
    60         _opts.type = (_canPlayType !== "no") ? "HtmlPlayer" : "JwpPlayer";
    70           .createElement("video")
    61     }
    71           .canPlayType('video/mp4; codecs="avc1.42E01E"');
       
    72         _opts.type = _canPlayType !== "no" ? "HtmlPlayer" : "JwpPlayer";
       
    73       }
    62 
    74 
    63     if (_rtmprgx.test(this.video)) {
    75       if (_rtmprgx.test(this.video)) {
    64         _opts.provider = "rtmp";
    76         _opts.provider = "rtmp";
    65         _opts.live = true;
    77         _opts.live = true;
    66     }
    78       }
    67 
    79 
    68     for (var i = 0; i < _props.length; i++) {
    80       for (var i = 0; i < _props.length; i++) {
    69         if (typeof this[_props[i]] !== "undefined") {
    81         if (typeof this[_props[i]] !== "undefined") {
    70             _opts[_props[i]] = this[_props[i]];
    82           _opts[_props[i]] = this[_props[i]];
    71         }
    83         }
    72     }
    84       }
    73 
    85 
    74     this.insertSubwidget(this.$, _opts);
    86       this.insertSubwidget(this.$, _opts);
       
    87     };
       
    88   };
       
    89 };
    75 
    90 
    76 };
    91 export { AutoPlayer };