说明

需要在PC端浏览器(Chrome)中播放直播视频,视频格式有H264/H265。有不少三方库可以实现。

通过video.js(支持H264,不支持H265)

videojs-contrib-hls embed

Video.js Example Embed

data-setup='{}'>

参考地址:

通过hls.js(支持H264,不支持H265)

pc play m3u8(hlsjs)

video {

width: 600px;

height: auto;

}

pc play m3u8(hlsjs)

var video = document.getElementById('video');

var videoSrc = 'http://ivi.bupt.edu.cn/hls/cctv1hd.m3u8';

if (Hls.isSupported()) {

var hls = new Hls();

hls.loadSource(videoSrc);

hls.attachMedia(video);

hls.on(Hls.Events.MANIFEST_PARSED, function () {

video.play();

});

}

// hls.js is not supported on platforms that do not have Media Source

// Extensions (MSE) enabled.

//

// When the browser has built-in HLS support (check using `canPlayType`),

// we can provide an HLS manifest (i.e. .m3u8 URL) directly to the video

// element through the `src` property. This is using the built-in support

// of the plain video element, without using hls.js.

//

// Note: it would be more normal to wait on the 'canplay' event below however

// on Safari (where you are most likely to find built-in HLS support) the

// video.src URL must be on the user-driven white-list before a 'canplay'

// event will be emitted; the last video event that can be reliably

// listened-for when the URL is not on the white-list is 'loadedmetadata'.

else if (video.canPlayType('application/vnd.apple.mpegurl')) {

video.src = videoSrc;

video.addEventListener('loadedmetadata', function () {

video.play();

});

}

参考地址:

通过EasyWasmPlayer(支持H264,也支持H265)

普通页面:

EasyWasmPlayer

H265播放器

列如:http://127.0.0.1:8080/flv/hls/stream.flv

在线演示

注意:本实例需要以服务方式启动

href="https://blog.csdn.net/weixin_43194037/article/details/108885134" target="_blank">搭建服务教程

播放

// 播放器回调函数

callbackfun = function (e) {

console.log(e);

}

// 播放按钮

var btn = document.getElementById('btn');

// 地址栏

var value = document.getElementById('value');

// 实例播放器

var player = new WasmPlayer(null, 'newplay', callbackfun, {

Height: true

})

//播放事件 传入地址播放

btn.onclick = function () {

player.play(value.value, 1);

console.log(value.value);

}

define/require页面:define([

"../lib/EasyWasmPlayer.js"

], function (EasyWasmPlayer) {

var MainView = {

// ...

afterRender: function () {

var that = this;

// 播放器回调函数,播放、暂停、全屏等会回调

var callbackfun = function (e) {

console.log(e);

};

// 地址栏

var value = document.getElementById('value');

// 实例播放器,注意这里为EasyWasmPlayer,不是WasmPlayer

var player = new EasyWasmPlayer(null, 'newplay', callbackfun, {

Height: true

});

// 播放按钮

var btn = document.getElementById('btn');

//播放事件 传入地址播放

btn.onclick = function () {

player.play(value.value, 1);

console.log(value.value);

}

},

};

// ...

});

注意:new WasmPlayer要改为new EasyWasmPlayer。

地址用相对地址"../lib/EasyWasmPlayer.js",不用"xx/yy/zz/videoplay/lib/EasyWasmPlayer.js"

参考:

注意:要使得EasyPlayer支持h265格式,需要将文件发布到http服务器上,如nginx。将ccc.html,EasyWasmPlayer.js,libDecoder.wasm放入$NGINX_HOME/html下,然后配置:server {

listen 7078;

charset utf-8;

proxy_connect_timeout 180;

proxy_send_timeout 180;

proxy_read_timeout 180;

location / {

root html;

index ccc.html;

}

}

root html 表示根目录为$NGINX_HOME/html

index ccc.html; 表示默认访问页为:ccc.html

采用EasyPlayer播放H265中遇到的问题(H264无问题)

tomcat部署,播放H265

将ccc.html,EasyWasmPlayer.js,libDecoder.wasm三个文件放入$TOMCAT_HOME/webapps/examples下,然后http://localhost:8080/examples/ccc.html访问,播放H265视频,报错:Uncaught (in promise) RuntimeError: abort(CompileError: WebAssembly.instantiate(): expected magic word 00 61 73 6d, found 3c 68 74 6d @+0) at Error

at WA (blob:http://localhost:8080/92fa365d-2fd3-4882-931c-bb6d344138aa:1:15306)

at PA (blob:http://localhost:8080/92fa365d-2fd3-4882-931c-bb6d344138aa:1:15458)

at FA (blob:http://localhost:8080/92fa365d-2fd3-4882-931c-bb6d344138aa:1:13489)

at blob:http://localhost:8080/92fa365d-2fd3-4882-931c-bb6d344138aa:1:14589

at FA (blob:http://localhost:8080/92fa365d-2fd3-4882-931c-bb6d344138aa:1:13494)

at blob:http://localhost:8080/92fa365d-2fd3-4882-931c-bb6d344138aa:1:14589

将文件部署到nginx的html下,问题解决。但为何在tomcat上报错呢?

分析

tomcat部署时出现CompileError: WebAssembly.instantiate(): expected magic word 00 61 73 6d, found 3c 68 74 6d @+0)的原因,通过浏览器Network查看,发现libDecoder.wasm 404错误,说明是未找到libDecoder.wasm导致。

通过nginx将/libDecoder.wasm重定向后,问题可解决。如:location /libDecoder.wasm {

proxy_pass http://xxxx/lib/libDecoder.wasm;

proxy_set_header Host $host:$server_port;

proxy_set_header X-Real-Ip $remote_addr;

}

这里xxxx/lib/用实际地址。

或者修改EasyWasmPlayer.js中libDecoder.wasm的路径。EasyWasmPlayer.js中搜索'libDecoder.wasm',改为:GA=T+"xxx/yyy/libDecoder.wasm";

这里xxx/yyy以实际地址替换。

如果通过springboot启动,可能不会报404错误,只报CompileError: WebAssembly.instantiate():。同样方式解决。

WasmPlayer is not defined

将文件EasyWasmPlayer.js,libDecoder.wasm拷贝到指定目录下。播放,报错:Uncaught ReferenceError: WasmPlayer is not defined

new WasmPlayer改为new EasyWasmPlayer即可。这里EasyWasmPlayer为文件头部define语句对应的实例。

要解决这个问题,也可以通过另一种变通的方法(不建议):

因为提示not defined,表示.js文件引的有问题或者用的时候上下文有问题。而不在前端框架中使用时,一点问题没有。

通过查看网页html,发现EasyWasmPlayer.js的引入语句为:

而不是:

在html中,找一个无关紧要的

我们通过nginx,将该文件的引用替换为EasyWasmPlayer.js的引入。location /portal/frm/portal/system.min.js {

proxy_pass http://localhost:7072/portal/xxx/yyy/videoplay/lib/EasyWasmPlayer.js;

proxy_set_header Host $host:$server_port;

proxy_set_header X-Real-Ip $remote_addr;

}

重启nginx后,问题解决。

EasyPlayer的其它说明libDecoder.wasm文件需要,且路径能访问到

EasyWasmPlayer.js不用放在根目录,能成功引入就行

html5支持h265吗,PC端播放H265相关推荐

  1. html5 h265播放器,PC端播放H265

    说明 需要在PC端浏览器(Chrome)中播放直播视频,视频格式有H264/H265.有不少三方库可以实现. 通过video.js(支持H264,不支持H265) videojs-contrib-hl ...

  2. 关于Android 竖屏录制,在PC端播放被逆时针旋转了90度

    更新: 事实上这是视频播放器的原因,使用自带播放器,win7上H264会被逆时针旋转90度,而win10上MPEG_4_SP会被逆时针旋转90度. 使用MediaRecorder录制视频,发现在PC端 ...

  3. PC端播放RTMP流(手机端无法播放)

    这是之前从网上搜到的资料保存下来,已经忘记是哪位大神的了 望见谅! 当前手机端不支持RTMP和RTSP 需要自己做播放器才可以进行支持 有效的RTMP直播源:(亲测可用!) rtmp://live.h ...

  4. H265网页视频播放器播放H265编码录像视频文件如何减缓卡顿情况?

    视频播放延时卡顿的问题从视频服务诞生以来就一直存在,即便是在技术发达的今天,延时卡顿问题仍然是不能完全解决的(不同视频流延时说明). TSINGSEE青犀视频研发团队开发的H265播放器播放录像文件时 ...

  5. web支持H265视频码流播放

    由于公司的产品经常与视频打交道,避免不了web端要支持视频播放,目前公司已经有成熟的web播放解决方案,但是可惜的是支持H264:虽然H264和H265只差一位,内部千差万别: 可以建议了解下H264 ...

  6. H265格式兼容各个浏览器web端播放方案

    可能有很多朋友会遇到H265格式的视频流无法播放,毕竟现在很多相机都支持h265了,确实有很多优点,但是它最大的问题就是很多浏览器无法播放,也有部分浏览器能够兼容h265,但是总不能让用户指定浏览器使 ...

  7. PC端和移动端都支持视频video自动播放的代码

    需求说明 今天有个朋友微信上说目前他们在做抖音短视频的内容创作,方向是国家级非物质文化遗产「汝瓷」,想在他们官方网站上增加短视频的功能,将抖音的内容页上传到网站上. 其实这个功能并不复杂,只需要开通上 ...

  8. 微信 小程序 之PC端 不支持 wx.previewMedia 方法 故用自定义轮播图进行 模拟照片视频的播放

    微信小程序 自带的方法 wx.previewMedia 预览图片和视频. 图片 wx.previewImage 支持PC端可以进行播放, 视频没有找到对应的方法 在真机和手机端都可以进项展示,PC端不 ...

  9. 无插件播放h265视频

    对于NVR设备,需要配web端来管理,包括NVR常用配置和视频预览.视频的预览,以前可以通过插件的方式来实现,IE通过ActiveX控件,其它浏览器通过NPAPI插件.NPAPI插件被谷歌抛弃掉,说是 ...

最新文章

  1. pytorch生成对抗示例
  2. hbase安装,以及安装前置hadoop(单节点)
  3. textAngular字体依赖
  4. java自定义注解为空值_java自定义注解
  5. tomcat架构分析(容器类)【转】
  6. Kafka文件存储机制那些事
  7. vs2013+EF6+Mysql
  8. tomcat 设置java内存_Tomcat 设置JVM内存大小
  9. 反质数问题,求不大于n的最大反质数
  10. 生成式对抗网络GAN
  11. 学习C语言,有哪些值得推荐的经典书籍?
  12. “猜猜红桃A在哪里”——android小游戏(入门学习必备)
  13. 360安全卫士隐藏广告日常去除小技巧
  14. Arcgis 连接PostgreSQL
  15. 如何自动生成目录,并设置目录格式(一看就懂)
  16. 推理的2种方式:演绎和归纳
  17. 【绝对原创】EFS加密文件真的可以解密!各位不要放弃哈~
  18. 分享你喜欢的杀毒软件
  19. java基础篇(11) 枚举类型
  20. 旧mac迁移到Mac21款m1后微信聊天记录文件显示未下载怎么办

热门文章

  1. 号外——安装ubantu操作系统16.04
  2. DFIG控制3: 风机模型和最基础的MPPT
  3. Vue系统指令(一)
  4. ASM 函数参数处理
  5. Category Archives: 机器学习
  6. P84-前端基础动画效果-动画3D复仇者联盟练习
  7. Python编程:从入门到实践(第二版)随书敲代码 第八章 函数
  8. python中datetime是什么意思_Python中time和datetime的区别与联系
  9. 阿里云学生机服务器开启端口
  10. 【Shell】执行shell脚本进入指定目录