tcplayer源码改造第五弹 -> 兼容sarafi/遨游

前序

简介

  • 主要介绍了基于tcplayer的源码改造,修复不兼容sarafi问题
  • 不涉及tcplayer的使用以及框架如何调用,详情请看腾讯云点播文档
  • 源码解析中有些注释是笔者加的,如需定位,请不要复制注释
  • 以下示例的代码为重新混淆压缩过,可能与原来的tcplayer.js函数名不同,不可直接复制使用,请务必跟着笔者一步步执行

人群

  • 不适合没有任何前端基础的小白,请谨慎观看

git地址

https://github.com/HaverLee1/hls-player

不兼容原因

Safari和遨游浏览器上未能调用hls.js文件

修复兼容性(各位客官请自定格式化代码)

搜索"(f.CDNPath + r)"定位到加载hls.js文件的代码,如下代码,代码中加入了笔者的注释

// 这一段代码中的i && g.IS_MAC && g.IS_SAFARI && !g.IS_IOS表示当当前浏览器是mac的sarafi时,直接将视频地址赋值给video标签的src参数
          if (!g.IS_ENABLED_MSE || !i && !o || g.IS_X5TBS && this.player.options.x5_player || i && g.IS_MAC && g.IS_SAFARI && !g.IS_IOS) {
            this.__type = t, this.el.src = e
          } else {
            var n = this, r = w[this.options.hls] || w["0.7.1"];
            i ? (this.__type = f.VideoType.M3U8, "undefined" == typeof window.Hls ? h.loadScript(f.unifyProtocol(this.player.options.encryptHls ? this.player.options.encryptHls : (f.CDNPath + r)), function () {
              n.__hlsLoaded.call(n, e)
            }) : this.__hlsLoaded(e)) : o && (this.__type = f.VideoType.FLV, "undefined" == typeof window.flvjs ? h.loadScript(f.unifyProtocol(f.CDNPath + "libs/flv.min.1.5.js"), function () {
              n.__flvLoaded.call(n, e)
            }) : this.__flvLoaded(e))
          }

修改成如下即可

if (!g.IS_ENABLED_MSE || !i && !o || g.IS_X5TBS && this.player.options.x5_player) {
              this.__type = t, this.el.src = e
            } else {
              var n = this, r = w[this.options.hls] || w["0.7.1"];
              i ? (this.__type = f.VideoType.M3U8, "undefined" == typeof window.Hls ? h.loadScript(f.unifyProtocol(this.player.options.encryptHls ? this.player.options.encryptHls : (f.CDNPath + r)), function () {
                n.__hlsLoaded.call(n, e)
              }) : this.__hlsLoaded(e)) : o && (this.__type = f.VideoType.FLV, "undefined" == typeof window.flvjs ? h.loadScript(f.unifyProtocol(f.CDNPath + "libs/flv.min.1.5.js"), function () {
                n.__flvLoaded.call(n, e)
              }) : this.__flvLoaded(e))
            }

相关推荐

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值