发布时间:2026-07-21阅读(1)
5G已来,直播、视频等垂直应用领域肯定会诞生一批"后浪型"公司。由于直播、视频的即时性能承担更大的信息量,因此成为各大厂运营/产品的主要信息输出方式。
但目前web形式的视频不管在性能或是体验上都有非常大的限制。主要原因无外乎国内各大浏览器厂商的利益关系。他们对H5的video能力做了非常多的限制。
为了解决上面一系列问题,终于有一款播放器软件站出来了 WXInlinePlayer。

wxinlineplayer 一款高性能的视频播放器解决方案。目前在 安防监控、直播及短视频领域 有非常多的定制化开发案例。并取得不错的效果。


独立解码依赖
使用场景
目前WXInlinePlayer兼容性已经覆盖以下主流浏览器
目前WASM的兼容性有了很大的改观,但在移动端,由于国内各个浏览器厂商实现不统一,因此需要考虑WASM不可用情况。WXInlinePlayer为了更好的应对兼容性,解码库编译出了 ASM.js 和 WASM.js 两个版本,同时提供降级判断,方便使用中进行相应的处理。
if(WXInlinePlayer.isSupport()){ WXInlinePlayer.init({ asmUrl: ./prod.all.asm.combine.js, wasmUrl: ./prod.all.wasm.combine.js, }); WXInlinePlayer.ready().then(()=>{ console.log(WXInlinePlayer ready); const player = new WXInlinePlayer({ url: ..., //播放地址 $container: document.getElementById(container), //绘制的canvas对象 hasVideo: true, //是否含有视频 hasAudio: true, //是否含有音频 volume: 1.0, //音量 muted: false, //是否静音 autoplay: true, //是否自动播放 loop: true, //循环播放 isLive: false, //是否是直播流 chunkSize: 128 * 1024, //解析块大小 默认256*1024 preloadTime: 5e2, //预加载事件 bufferingTime: 1e3, //缓冲事件 cacheSegmentCount: 64, //内部最大缓存帧数量 customLoader: null, //自定义loader }); });}
使用插件
<!DOCTYPE html><html><head> <meta charset="UTF-8" /> <title>WXInlinePlayer</title> <style> * { margin: 0; padding: 0; } html, body { width: 100%; height: 100%; } </style></head><body> <canvas id="container" width="800" height="450"></canvas> <script src="./index.js"></script> <script> if (WXInlinePlayer.isSupport()) { WXInlinePlayer.init({ asmUrl: ./prod.baseline.asm.combine.js, wasmUrl: ./prod.baseline.wasm.combine.js }); WXInlinePlayer.ready().then(() => { const player = new WXInlinePlayer({ url: https://static.petera.cn/mm.flv, $container: document.getElementById(container), hasVideo: true, hasAudio: true, volume: 1.0, muted: false, autoplay: true, loop: true, isLive: false, chunkSize: 128 * 1024, preloadTime: 5e2, bufferingTime: 1e3, cacheSegmentCount: 64, customLoader: null }); const { userAgent } = navigator; const isWeChat = /MicroMessenger/i.test(userAgent); if (!isWeChat) { alert(click to play!); document.body.addEventListener(click, () => { player.play(); }); } }); } </script></body></html>
WXInlinePlayer也提供了performance事件帮助使用者了解当前的解码性能,便于提示用户降级到后备方案。
player.on(performance, ({averageDecodeCost, averageUnitDuration})=>{ const prop = averageUnitDuration / averageDecodeCost; if(prop >= 2.0){ console.log(good performance); }else if(prop < 2.0 && prop >= 1.0){ console.log(ok, thats fine); }else{ console.log(bad performance); }});
WXInlinePlayer.ready().then(()=>{ const player = new WXInlinePlayer({/*...*/}); // 播放 document.body.addEventListener(click, ()=>{ player.play(); }); // 暂停 player.pause(); // 音量 const volume = player.volume(); // get volume player.volume(volume); // set volume // 获取当前播放时间 player.on(timeUpdate, ()=>{ let currentTime = player.getCurrentTime(); currentTime = currentTime <= 0 ? 0 : currentTime; });});
事件
未来随着5G及更高性能的硬件设备的发展WASM会逐渐渗透在多个领域。浏览器依托WASM技术必将会为未来扩展音视频处理的通用能力提供了想象的空间。目前WXInlinePlayer已经更新到了1.3.3版本,随着越来越多公司的使用,WXInlinePlayer在现版本已经逐步稳定。在后期中,我们将进一步尝试增强WXInlinePlayer的性能和易用性,包括不限于:
# demo示例https://qiaozi-tech.github.io/WXInlinePlayer/example/index.html# 项目地址https://github.com/qiaozi-tech/WXInlinePlayer
ok,就介绍到这里。喜欢的朋友可以去看下哈~ 欢迎一起交流。
Copyright © 2024 有趣生活 All Rights Reserve吉ICP备19000289号-5 TXT地图HTML地图XML地图