参军是什么官职| 沙拉酱可以做什么美食| 想要孩子需要做什么检查| 湾湾是什么意思| 双鱼座有什么特点| 吐血是什么原因| 上海市长什么级别| 子宫内膜为什么会增厚| 出汗多是什么原因| 硬脂酸镁是什么| 二月九号是什么星座| 脑血管堵塞会有什么后果| 单招是什么学历| 杜字五行属什么| 女性尿频尿急吃什么药| 什么东西能加不能减| 牙齿松动了有什么办法能固齿吗| 为什么睡不着觉会胡思乱想| 十月份什么星座| 北洋军阀是什么意思| 身体铅超标有什么危害| 河蚌为什么没人吃| 俄罗斯用什么货币| 洗白是什么意思| 肾结石忌口什么| 波澜壮阔是什么意思| z值是什么意思| 肝脏是什么功能| 皮肤发白一块一块的是什么病| 黄瓜苦是什么原因| 梦见生孩子是什么意思解梦| 十二指肠球部溃疡吃什么药| 红细胞数目偏高是什么意思| 我宣你是什么意思| 猫发烧吃什么药| 毛血旺是什么| 10.16是什么星座| 水金龟属于什么茶| 什么是功能性消化不良| 车加昆念什么| 镇长什么级别| 小孩智力发育迟缓挂什么科| 安徽简称什么| 克服是什么意思| 天梭表什么档次| 肺部条索灶是什么意思| 梦见头上长虱子是什么意思| qn医学上是什么意思| 增致牛仔属于什么档次| 栉风沐雨是什么意思| 吃什么有助于睡眠效果好| 天网是什么意思| 四月初一是什么星座| ivd是什么意思| 狗可以吃什么| 心跳过快有什么危害| 送老爸什么礼物| 干咳无痰是什么原因| 什么颜色最显白| 梦到吃梨是什么意思| 主任医师是什么级别| 女性绝经有什么征兆| 解尿支原体是什么| 微创手术是什么| 西瓜什么时候成熟| 孤枕难眠什么意思| 吃什么食物补钙最快| 荷花和莲花有什么区别| 宝宝拉肚子有粘液是什么原因| 磁共振平扫检查什么| 一什么土| 7年之痒是什么意思| 手掌很红是什么原因| 不造是什么意思| 戒指带中指什么意思| 拘留所和看守所有什么区别| 中元节会开什么生肖| 八朵玫瑰花代表什么意思| 千米的字母是什么| 腹直肌分离是什么意思| 晨咳是什么原因引起的| 粉饼是干什么用的| 鱼油什么时候吃最好| 口腔发苦是什么原因| 盐为什么要加碘| 气虚吃什么中成药| 米其林是什么意思| 尼维达手表什么档次| 女人的网名叫什么好听| 喉咙痛去药店买什么药| 红班狠疮的早期症状是什么| b型血阳性是什么意思| 男人下面胀痛什么原因造成呢| 禾字五行属什么| 手脚经常发麻是什么原因| z什么意思| 碳酸氢钠是什么| 黄山四绝指的是什么| 可见原始心管搏动是什么意思| 海带和什么不能一起吃| 流鼻涕吃什么药好| 晚上吃什么减肥效果最好| 男人胸前有痣代表什么意思| 没有生抽可以用什么代替| 孕妇缺铁对胎儿有什么影响| 卡地亚蓝气球什么档次| 唐朝以后是什么朝代| 身份证有什么用| 文化底蕴是什么意思| 白羊座后面是什么星座| 有什么蔬菜| 热射病是什么| 气虚便秘吃什么中成药| 硌脚是什么意思| 无创什么时候出结果| 槟榔是什么味道| 疮疖是什么样子图片| 桓是什么意思| 经常生病是什么原因| 什么样的人容易得脑梗| 鼻窦炎用什么药效果最好| 西米是什么字| 肌酐高说明什么问题| 白球比低是什么原因| 5.3什么星座| 十一月二十九是什么星座| nafion溶液是什么| 舅舅的儿子叫什么| 心脏难受是什么原因| 不耐受和过敏有什么区别| 开什么节什么的成语| 阻生牙是什么意思| 七宗罪分别是什么| 胆囊炎能吃什么| 医院查怀孕做什么检查| 中央党校校长是什么级别| 11月18日什么星座| 牛肉烧什么好吃| 血管炎不能吃什么食物| 早搏的症状是什么表现| 五朵玫瑰花代表什么意思| 省委副书记什么级别| 儿童回春颗粒主要治什么| 顺钟向转位是什么意思| 巳时属什么生肖| 北京属于什么方向| 什么水果去湿气效果最好| 隐血弱阳性是什么意思| 梦见别人开车翻车是什么预兆| 水瓶座什么象| 万能输血者是什么血型| 切记是什么意思| 精湛是什么意思| 填充鼻子最好的材料是什么| 手抓饼里面夹什么好吃| elisa是什么检测方法| 四面楚歌是什么生肖| 夏季有什么花| 大三阳转小三阳意味着什么| 低盐饮食有利于预防什么疾病| 女人性冷淡吃什么药效果好| 发烧不能吃什么水果| 怀孕16周要做什么检查| 葡萄什么时候成熟| 合欢树为什么叫鬼树| 肿物是什么意思| hivab是什么检测| 乳液是什么| 肝火胃火旺盛吃什么药| 均可是什么意思| ibm是做什么的| 四月十四日是什么节日| 轻微脑震荡有什么症状| 肌肉痛吃什么药| 当医生学什么专业| daily是什么意思| 什么去甲醛最快有效| 枣子什么时候成熟| 中介什么意思| 丹参治什么病| 为什么会长口腔溃疡| 口腔溃疡缺乏什么维生素| 五条杠什么牌子| 左腿发麻是什么病征兆| 阿司匹林是什么药| 荨麻疹长什么样| 什么时候解放台湾| 蔡徐坤粉丝名叫什么| 养肝吃什么好| 2.1是什么星座| 吃金针菇有什么好处| 休息是什么意思| 茯苓的作用是什么| 慢性疾病都包括什么病| 心属于五行属什么| 石见读什么| 铁蛋白高吃什么食物好| 早上吃什么早餐最好| 鸡蛋白过敏指的是什么| 粘胶是什么材质| 为宜是什么意思| surprise是什么意思| lo娘是什么意思| 茄子与什么相克| 农历11月11日是什么星座| 男占258女占369什么意思| 武则天是什么朝代的| 筠字五行属什么| 淋巴结用什么药效果好| hyc是什么牌子| 月经量少吃什么好| 起付线是什么意思| 木兮是什么意思| 小粉是什么粉| 宫颈纳囊多发是什么意思| 等效球镜是什么意思| 头发全白是什么病| 皮肤容易过敏是什么原因| 心慌心闷是什么原因| 风声鹤唳是什么意思| 晚上喝蜂蜜水有什么好处和坏处| 查岗是什么意思| 大豆油是什么豆做的| 妇科养荣胶囊主治什么| 宝宝反复发烧是什么原因| 吃什么食物对胰腺好| 梦见眉毛掉了什么预兆| 笑口常开是什么生肖| dsa是什么| 梦到活人死了是什么预兆| 可乐是什么做的| 甲状腺有血流信号是什么意思| 煮玉米加盐有什么好处| 梦见挖坟墓预示什么| 乙字五行属什么| 2023属什么生肖| 什么的兵马俑| emba是什么| 内热是什么原因引起的怎么调理| 麻婆豆腐是什么菜系| 当兵什么时候体检| 谷氨酸高是什么原因| 童心未泯是什么意思| 降血糖吃什么菜| 喘不过气是什么原因| 代偿期和失代偿期是什么意思| 灰配什么颜色好看| 白细胞低是什么原因造成的| 什么药可以降尿酸| 颈椎病挂号挂什么科| 戊肝阳性是什么意思| 苏联为什么解体| 元老是什么意思| 九二共识是什么意思| 是什么梗| 什么杯子喝水最健康| camel是什么意思| 狐臭是什么引起的| 一语惊醒梦中人是什么意思| 擦伤挂什么科| 阳盛阴衰是什么意思| 非萎缩性胃炎是什么意思| 什么食物含硒量最高| 艾滋病中期有什么症状| 百度

川山甲控股股东合计质押1.50亿股 用于控股股东贷款

Video.js Blog

Gary Katsevman2025-08-04

Feature Spotlight: Middleware

百度 韧性基础:具有张力的国家治理结构中国特色社会主义制度的韧性从哪里来?其基础就是在改革开放过程中锻造的、具有张力的国家治理结构。

Middleware is one of the cool new features that is coming to Video.js in version 6.0

With middleware, you are now able to interact with and change how the player and the tech talk to each other. The tech is Video.js's abstraction from the player, separating the player API from the playback technology. With techs, we can plug things like a Flash fallback or a Youtube embed into Video.js without changing the external API or the look-and-feel of the player.

Video.js middleware are like Express middleware but routes are based on video MIME types.

A lot of Video.js users may be familiar with middleware from projects like Express. Video.js middleware isn't that different from those. In both cases you register your middleware against a particular route to call down the chain when the route is triggered. In Express, routes are based on the url paths. In Video.js, these routes are based on the video MIME type. And, like Express, there are "star" (*) middleware that match all routes.

There are two important pieces to be aware of with middleware:

  1. dynamic source handling

  2. intercepting the player and tech interactions.

A Video Catalog

With the dynamic source handling, you could load video with a custom type and source and resolve it asynchronously. A good example for this is a video catalog system. The page can be rendered with a specific catalog ID and a special MIME type, like so:

<video controls class="video-js">
  <source src="123" type="video/my-catalog">
</video>

Then, you could register a middleware for that route -- the type video/my-catalog.

// middleware methods get the player instance as an argument
videojs.use('video/my-catalog', function(player) {

  // middleware are expected to return an object with the methods on it.
  // It can be a plain object or an instance of something.
  return {

    // setSource allows you to tell Video.js whether you're going to be handling the source or not
    setSource(srcObj, next) {
      const id = srcObj.src;

      videojs.xhr({
        uri: '/getVideo?id=' + id
      }, function(err, res, body) {

        // pass null as the first argument to say everything is going fine and we can handle it.
        next(null, {
          src: body.sourceUrl,
          type: body.sourceType
        })
      });
    }
  };
});

Then, when Video.js initializes, it'll go through and call the middleware that are set for video/my-catalog.

Server-Side Ad Insertion

Server Side Ad Insertion (SSAI) is a great fit for middleware. It showcases the ability to intercept the play and tech interactions. For example, you have a 30 seconds ad followed by a five minute video in your HLS manifest. You want the timeline to display the ad time and the content time appropriate when each is playing. Right now, the duration displayed will be the combined duration of five minutes and 30 seconds (5:30). The solution is to add a middleware that knows when the ad is being played and tells the player that the duration is 30 seconds and when the content is playing that the duration is five minutes.

// register a star-middleware because HLS has two mimetypes
videojs.use('*', function(player) {
  return {
    setSource(srcObj, next) {
      const type = srcObj.type;

      if (type !== 'application/x-mpegurl' && type !== 'application/vnd.apple.mpegurl') {

        // call next with an error to signal you cannot handle the source
        next(new Error('Source is not an HLS source'));
      } else {

        // in here we know we're playing back an HLS source.
        // We don't want to do anything special for it, so, pass along the source along with a null.
        next(null, srcObj);
      }
    },

    // this method gets called on the tech and then up the middleware chain providing the values as you go along
    duration(durationFromTech) {
      if (areWeCurrentlyPlayingAnAd(durationFromTech)) {
        // since we're now in an ad, return the ad duration
        // in a real example you'd calculate this based on your playlist
        // rather than hardcode a value in here
        return 30;
      } else {
        // we're playing back content, so, return that duration
        return 5 * 60;
      }
    }
  }
});

Playbackrate Adjustment - A Case Study

A simple but interesting middleware to look at is the playbackrate-adjuster. This middleware will change the times of the controls depending on the current rate. For example, if you're playing back a 20 minute video and change the rate to 2x, the controls will adjust to display 10 minutes. Let's take a look at the code.

videojs.use('*', function(player) {
  /* ... */

  return {
    setSource(srcObj, next) {
      next(null, srcObj);
    },

    duration(dur) {
      return dur / player.playbackRate();
    },

    /* ... */
  };
});

So, here, we attach a star-middleware because we want to have it applied to any video, regardless of the MIME type. In setSource, we also call next directly with null and the srcObj because we want to use this middleware with any and all sources. We also set up our duration method to take in the duration from the previous middleware and divide it by the playback rate we get from the player.

If you look at the code you can see some other methods next to duration. They're there to make sure other methods that rely on timing get updated. The two methods to notice are currentTime and setCurrentTime. currentTime gets called when we want to know what the current time is. setCurrentTime is called when we're seeking. Because the user is seeking in the shifted time, we want to apply our change operation in reverse. Instead of dividing it, we want to multiply it.

    currentTime(ct) {
      return ct / player.playbackRate();
    },

    setCurrentTime(ct) {
      return ct * player.playbackRate();
    },

If you were to apply what we've done so far, you'll notice that the nothing changes, the control bar is still showing a duration of 20 minutes. This is because as far as Video.js knows, nothing has changed. So, we need to tell Video.js that the duration has changed. We can do that by storing the tech that Video.js gives us after source selection is complete.

videojs.use('*', function(player) {
  let tech;

  return {
    setTech(newTech) {
      tech = newTech;
    }

    /* ... */
  };
});

And then, when the ratechange event triggers, we tell Video.js that the duration has changed and Video.js will update the controls accordingly:

videojs.use('*', function(player) {
  let tech;

  player.on('ratechange', function() {
    tech.trigger('durationchange');
    tech.trigger('timeupdate');
  });

  return {
   /* ... */
  }
});

You can see a live example here and the complete code here.

长期便秘是什么原因引起的 胃病吃什么药最好 慢性咽炎用什么药 宫保鸡丁是什么菜系 脑科属于什么科
缺血吃什么补血最快 男生喜欢什么样的女生 吃东西就吐是什么原因 失眠看什么科 冻感冒了吃什么药
尿路感染吃什么药效果好 花生不能和什么一起吃 3000年前是什么朝代 黄疸高吃什么药 情绪价值是什么意思
知了猴是什么东西 肛门瘙痒用什么药最好 感冒为什么会打喷嚏 高铁上为什么没有e座 骨加客念什么
为什么午睡起来会头疼hcv8jop9ns2r.cn 人为什么会做梦科学解释hcv7jop9ns3r.cn 知更鸟是什么意思hcv8jop5ns0r.cn 蒲公英和玫瑰花一起泡有什么功效hanqikai.com 1996属鼠的是什么命hcv9jop6ns3r.cn
高血压应该吃什么hcv8jop1ns1r.cn 上不来气是什么原因hcv8jop6ns1r.cn 糖耐量异常是什么意思hcv9jop2ns2r.cn 绿色食品是什么hcv9jop6ns0r.cn 副省长什么级别hcv9jop2ns1r.cn
头七有什么规矩hcv7jop6ns8r.cn 噤若寒蝉是什么意思hcv8jop1ns5r.cn sapphire手表什么牌子520myf.com 正能量是什么意思hcv8jop4ns3r.cn 问诊是什么意思hcv9jop8ns1r.cn
缺席是什么意思hcv7jop9ns8r.cn 舌苔白厚是什么原因hcv8jop6ns2r.cn 流连忘返的返是什么意思hcv8jop8ns9r.cn 住房公积金缴存基数是什么意思hcv8jop1ns2r.cn 什么水果美白hcv8jop6ns2r.cn
百度