HTML5基于flash实现播放RTMP协议视频的示例代码


Posted in HTML / CSS onDecember 04, 2020

HTML5基于flash实现播放RTMP协议视频,具体代码如下所示:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Video.js 7</title>
	<link href="css/video-js.min.css" rel="stylesheet">
	<style>
		body{background-color: #191919}
		.m{ width: 640px; height: 264px; margin-left: auto; margin-right: auto; margin-top: 100px; }
	</style>
</head>

<body>
	<div class="m">
		<video id="rtmpVideo" class="video-js vjs-default-skin vjs-big-play-centered vjs-fluid" controls preload="auto" width="640" height="264" data-setup='{ "html5" : { "nativeTextTracks" : false } }'>
		
		  </video>
		<script src="js/video.min.js"></script>
		<script src="js/videojs-flash.min.js"></script>
		  <script type="text/javascript">
		   //设置中文
		  videojs.addLanguage('zh-CN', {
			  "Play": "播放",
			  "Pause": "暂停",
			  "Current Time": "当前时间",
			  "Duration": "时长",
			  "Remaining Time": "剩余时间",
			  "Stream Type": "媒体流类型",
			  "LIVE": "直播",
			  "Loaded": "加载完毕",
			  "Progress": "进度",
			  "Fullscreen": "全屏",
			  "Non-Fullscreen": "退出全屏",
			  "Mute": "静音",
			  "Unmute": "取消静音",
			  "Playback Rate": "播放速度",
			  "Subtitles": "字幕",
			  "subtitles off": "关闭字幕",
			  "Captions": "内嵌字幕",
			  "captions off": "关闭内嵌字幕",
			  "Chapters": "节目段落",
			  "Close Modal Dialog": "关闭弹窗",
			  "Descriptions": "描述",
			  "descriptions off": "关闭描述",
			  "Audio Track": "音轨",
			  "You aborted the media playback": "视频播放被终止",
			  "A network error caused the media download to fail part-way.": "网络错误导致视频下载中途失败。",
			  "The media could not be loaded, either because the server or network failed or because the format is not supported.": "视频因格式不支持或者服务器或网络的问题无法加载。",
			  "The media playback was aborted due to a corruption problem or because the media used features your browser did not support.": "由于视频文件损坏或是该视频使用了你的浏览器不支持的功能,播放终止。",
			  "No compatible source was found for this media.": "无法找到此视频兼容的源。",
			  "The media is encrypted and we do not have the keys to decrypt it.": "视频已加密,无法解密。",
			  "Play Video": "播放视频",
			  "Close": "关闭",
			  "Modal Window": "弹窗",
			  "This is a modal window": "这是一个弹窗",
			  "This modal can be closed by pressing the Escape key or activating the close button.": "可以按ESC按键或启用关闭按钮来关闭此弹窗。",
			  ", opens captions settings dialog": ", 开启标题设置弹窗",
			  ", opens subtitles settings dialog": ", 开启字幕设置弹窗",
			  ", opens descriptions settings dialog": ", 开启描述设置弹窗",
			  ", selected": ", 选择",
			  "captions settings": "字幕设定",
			  "Audio Player": "音频播放器",
			  "Video Player": "视频播放器",
			  "Replay": "重播",
			  "Progress Bar": "进度小节",
			  "Volume Level": "音量",
			  "subtitles settings": "字幕设定",
			  "descriptions settings": "描述设定",
			  "Text": "文字",
			  "White": "白",
			  "Black": "黑",
			  "Red": "红",
			  "Green": "绿",
			  "Blue": "蓝",
			  "Yellow": "黄",
			  "Magenta": "紫红",
			  "Cyan": "青",
			  "Background": "背景",
			  "Window": "视窗",
			  "Transparent": "透明",
			  "Semi-Transparent": "半透明",
			  "Opaque": "不透明",
			  "Font Size": "字体尺寸",
			  "Text Edge Style": "字体边缘样式",
			  "None": "无",
			  "Raised": "浮雕",
			  "Depressed": "压低",
			  "Uniform": "均匀",
			  "Dropshadow": "下阴影",
			  "Font Family": "字体库",
			  "Proportional Sans-Serif": "比例无细体",
			  "Monospace Sans-Serif": "单间隔无细体",
			  "Proportional Serif": "比例细体",
			  "Monospace Serif": "单间隔细体",
			  "Casual": "舒适",
			  "Script": "手写体",
			  "Small Caps": "小型大写字体",
			  "Reset": "重启",
			  "restore all settings to the default values": "恢复全部设定至预设值",
			  "Done": "完成",
			  "Caption Settings Dialog": "字幕设定视窗",
			  "Beginning of dialog window. Escape will cancel and close the window.": "开始对话视窗。离开会取消及关闭视窗",
			  "End of dialog window.": "结束对话视窗"
			});

		   videojs.options.flash.swf = 'js/video-js.swf';

		   // 初始化视频,设为全局变量
var myPlayer = videojs('rtmpVideo', {
    autoplay: true,
    controls: true,//控制条
  
    muted: true,// 静音
    preload: "auto",// 预加载
    language: "zh-CN",// 初始化语言
    playbackRates: [1, 2, 3, 4, 5, 8, 10, 20],// 播放速度
	 'techOrder': ['flash'],
          
            sources: [{
                    /*rtmp://live.hkstv.hk.lxdns.com/live/hks*/
                src: 'rtmp://www.uav-space.com/vod2/uspace3.mp4',   //这里设置你的播放资源,
                type: 'rtmp/flv'
            }]
}, function () {
    console.log("--------------成功初始化视频--------------");
    myPlayer.one("playing", function () {         // 监听播放
        console.log("开始播放");
    });
    myPlayer.one("error", function (error) {      // 监听错误
        console.error("监听到异常,错误信息:%o",error);
    });
});
		</script>
	</div>

</body>
</html>

另外,可能需要更新flash,更新完重启电脑,然后点击允许flash就可以了

!!!看到评论里有人说不执行,我特地把网盘资源下载下来又看看了,没问题的,视频没反应的,可能是因为你用的文件协议打开html的,要用http格式打开啊,自己搞的apache吧

demo网盘下载链接:

链接: https://pan.baidu.com/s/1i7ATxe78jDaLnZM4YRb3tA 提取码: uqsa

2020年8月28:补充 video class 上加上vjs-fluid 可以实现resize效果,demo上估计没有吧

到此这篇关于HTML5基于flash实现播放RTMP协议视频的示例代码的文章就介绍到这了,更多相关html5播放RTMP协议视频内容请搜索三水点靠木以前的文章或继续浏览下面的相关文章,希望大家以后多多支持三水点靠木!

HTML / CSS 相关文章推荐
利用css3实现的简单的鼠标悬停按钮
Nov 04 HTML / CSS
CSS3 animation实现逐帧动画效果
Jun 02 HTML / CSS
css3实现蒙版弹幕功能
Jun 18 HTML / CSS
你不知道的5个HTML5新功能
Jun 28 HTML / CSS
5分钟弄清楚html5的drag and drop(小结)
Apr 10 HTML / CSS
html5菜单折纸效果
Apr 22 HTML / CSS
实例讲解使用SVG制作loading加载动画的方法
Apr 05 HTML / CSS
HTML5+CSS3实现机器猫
Oct 17 HTML / CSS
html5实现图片转圈的动画效果——让页面动起来
Oct 16 HTML / CSS
Canvas绘制浮动球效果的示例
Dec 29 HTML / CSS
HTML5自定义属性的问题分析
Aug 16 HTML / CSS
使用CSS实现小三角边框原理解析
Nov 07 HTML / CSS
前端水印的简单实现代码示例
Dec 02 #HTML / CSS
html5跳转小程序wx-open-launch-weapp踩坑
Dec 02 #HTML / CSS
Bootstrap File Input文件上传组件
Dec 01 #HTML / CSS
HTML5单选框、复选框、下拉菜单、文本域的实现代码
Dec 01 #HTML / CSS
Html5页面点击遮罩层背景关闭遮罩层
Nov 30 #HTML / CSS
使用HTML5加载音频和视频的实现代码
Nov 30 #HTML / CSS
Canvas实现放大镜效果完整案例分析(附代码)
Nov 26 #HTML / CSS
You might like
php获得用户ip地址的比较不错的方法
2014/02/08 PHP
php中的路径问题与set_include_path使用介绍
2014/02/11 PHP
PHP实现基于mysqli的Model基类完整实例
2016/04/08 PHP
thinkphp3.x连接mysql数据库的方法(具体操作步骤)
2016/05/19 PHP
PHP使用imagick扩展实现合并图像的方法
2017/04/25 PHP
php输出反斜杠的实例方法
2019/09/19 PHP
firefox中JS读取XML文件
2006/12/21 Javascript
jQuery弹出层始终垂直居中相对于屏幕或当前窗口
2013/04/01 Javascript
JavaScript笔记之数据属性和存储器属性
2016/03/31 Javascript
JavaScript中的 attribute 和 jQuery中的 attr 方法浅析
2017/01/04 Javascript
jQuery源码分析之sizzle选择器详解
2017/02/13 Javascript
防止重复发送 Ajax 请求
2017/02/15 Javascript
javascript用rem来做响应式开发
2018/01/13 Javascript
详解vue 路由跳转四种方式 (带参数)
2019/04/28 Javascript
JavaScript仿京东秒杀倒计时
2020/03/17 Javascript
用Python写的图片蜘蛛人代码
2012/08/27 Python
Python实现读取目录所有文件的文件名并保存到txt文件代码
2014/11/22 Python
分享几道你可能遇到的python面试题
2017/07/24 Python
详解python中asyncio模块
2018/03/03 Python
django项目搭建与Session使用详解
2018/10/10 Python
解决Python中list里的中文输出到html模板里的问题
2018/12/17 Python
对python3 sort sorted 函数的应用详解
2019/06/27 Python
Python上下文管理器全实例详解
2019/11/12 Python
Python使用matplotlib绘制Logistic曲线操作示例
2019/11/28 Python
如何基于pythonnet调用halcon脚本
2020/01/20 Python
python实现串口通信的示例代码
2020/02/10 Python
Python全面分析系统的时域特性和频率域特性
2020/02/26 Python
python 将视频 通过视频帧转换成时间实例
2020/04/23 Python
基于python SMTP实现自动发送邮件教程解析
2020/06/02 Python
简单总结CSS3中视窗单位Viewport的常见用法
2016/02/04 HTML / CSS
ASOS英国官网:英国在线时装和化妆品零售商
2017/05/19 全球购物
学生自我鉴定格式及范文
2014/09/16 职场文书
中学生运动会新闻稿
2014/09/24 职场文书
财务部岗位职责范本
2015/04/14 职场文书
调解协议书范本
2016/03/21 职场文书
创业计划书之韩国烧烤店
2019/09/19 职场文书