前序
简介
- 主要介绍了基于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))
}