经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 软件/图像 » Flash » 查看文章
HTML5基于flash实现播放RTMP协议视频的示例代码
来源:jb51  时间:2020/12/8 9:20:01  对本文有异议

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

  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Video.js 7</title>
  6. <link href="css/video-js.min.css" rel="stylesheet">
  7. <style>
  8. body{background-color: #191919}
  9. .m{ width: 640px; height: 264px; margin-left: auto; margin-right: auto; margin-top: 100px; }
  10. </style>
  11. </head>
  12.  
  13. <body>
  14. <div class="m">
  15. <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 } }'>
  16. </video>
  17. <script src="js/video.min.js"></script>
  18. <script src="js/videojs-flash.min.js"></script>
  19. <script type="text/javascript">
  20. //设置中文
  21. videojs.addLanguage('zh-CN', {
  22. "Play": "播放",
  23. "Pause": "暂停",
  24. "Current Time": "当前时间",
  25. "Duration": "时长",
  26. "Remaining Time": "剩余时间",
  27. "Stream Type": "媒体流类型",
  28. "LIVE": "直播",
  29. "Loaded": "加载完毕",
  30. "Progress": "进度",
  31. "Fullscreen": "全屏",
  32. "Non-Fullscreen": "退出全屏",
  33. "Mute": "静音",
  34. "Unmute": "取消静音",
  35. "Playback Rate": "播放速度",
  36. "Subtitles": "字幕",
  37. "subtitles off": "关闭字幕",
  38. "Captions": "内嵌字幕",
  39. "captions off": "关闭内嵌字幕",
  40. "Chapters": "节目段落",
  41. "Close Modal Dialog": "关闭弹窗",
  42. "Descriptions": "描述",
  43. "descriptions off": "关闭描述",
  44. "Audio Track": "音轨",
  45. "You aborted the media playback": "视频播放被终止",
  46. "A network error caused the media download to fail part-way.": "网络错误导致视频下载中途失败。",
  47. "The media could not be loaded, either because the server or network failed or because the format is not supported.": "视频因格式不支持或者服务器或网络的问题无法加载。",
  48. "The media playback was aborted due to a corruption problem or because the media used features your browser did not support.": "由于视频文件损坏或是该视频使用了你的浏览器不支持的功能,播放终止。",
  49. "No compatible source was found for this media.": "无法找到此视频兼容的源。",
  50. "The media is encrypted and we do not have the keys to decrypt it.": "视频已加密,无法解密。",
  51. "Play Video": "播放视频",
  52. "Close": "关闭",
  53. "Modal Window": "弹窗",
  54. "This is a modal window": "这是一个弹窗",
  55. "This modal can be closed by pressing the Escape key or activating the close button.": "可以按ESC按键或启用关闭按钮来关闭此弹窗。",
  56. ", opens captions settings dialog": ", 开启标题设置弹窗",
  57. ", opens subtitles settings dialog": ", 开启字幕设置弹窗",
  58. ", opens descriptions settings dialog": ", 开启描述设置弹窗",
  59. ", selected": ", 选择",
  60. "captions settings": "字幕设定",
  61. "Audio Player": "音频播放器",
  62. "Video Player": "视频播放器",
  63. "Replay": "重播",
  64. "Progress Bar": "进度小节",
  65. "Volume Level": "音量",
  66. "subtitles settings": "字幕设定",
  67. "descriptions settings": "描述设定",
  68. "Text": "文字",
  69. "White": "白",
  70. "Black": "黑",
  71. "Red": "红",
  72. "Green": "绿",
  73. "Blue": "蓝",
  74. "Yellow": "黄",
  75. "Magenta": "紫红",
  76. "Cyan": "青",
  77. "Background": "背景",
  78. "Window": "视窗",
  79. "Transparent": "透明",
  80. "Semi-Transparent": "半透明",
  81. "Opaque": "不透明",
  82. "Font Size": "字体尺寸",
  83. "Text Edge Style": "字体边缘样式",
  84. "None": "无",
  85. "Raised": "浮雕",
  86. "Depressed": "压低",
  87. "Uniform": "均匀",
  88. "Dropshadow": "下阴影",
  89. "Font Family": "字体库",
  90. "Proportional Sans-Serif": "比例无细体",
  91. "Monospace Sans-Serif": "单间隔无细体",
  92. "Proportional Serif": "比例细体",
  93. "Monospace Serif": "单间隔细体",
  94. "Casual": "舒适",
  95. "Script": "手写体",
  96. "Small Caps": "小型大写字体",
  97. "Reset": "重启",
  98. "restore all settings to the default values": "恢复全部设定至预设值",
  99. "Done": "完成",
  100. "Caption Settings Dialog": "字幕设定视窗",
  101. "Beginning of dialog window. Escape will cancel and close the window.": "开始对话视窗。离开会取消及关闭视窗",
  102. "End of dialog window.": "结束对话视窗"
  103. });
  104.  
  105. videojs.options.flash.swf = 'js/video-js.swf';
  106.  
  107. // 初始化视频,设为全局变量
  108. var myPlayer = videojs('rtmpVideo', {
  109. autoplay: true,
  110. controls: true,//控制条
  111. muted: true,// 静音
  112. preload: "auto",// 预加载
  113. language: "zh-CN",// 初始化语言
  114. playbackRates: [1, 2, 3, 4, 5, 8, 10, 20],// 播放速度
  115. 'techOrder': ['flash'],
  116. sources: [{
  117. /*rtmp://live.hkstv.hk.lxdns.com/live/hks*/
  118. src: 'rtmp://www.uav-space.com/vod2/uspace3.mp4', //这里设置你的播放资源,
  119. type: 'rtmp/flv'
  120. }]
  121. }, function () {
  122. console.log("--------------成功初始化视频--------------");
  123. myPlayer.one("playing", function () { // 监听播放
  124. console.log("开始播放");
  125. });
  126. myPlayer.one("error", function (error) { // 监听错误
  127. console.error("监听到异常,错误信息:%o",error);
  128. });
  129. });
  130. </script>
  131. </div>
  132.  
  133. </body>
  134. </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协议视频内容请搜索w3xue以前的文章或继续浏览下面的相关文章,希望大家以后多多支持w3xue!

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号