html网页播放多个视频的几种方法

  发布时间:2024-03-04 15:56:44   作者: 阿龍1787   我要评论
本文主要介绍了html网页播放多个视频的几种方法,包含iframe标签,VLC插件和一些常见的js插件,具有一定的参考价值,感兴趣的可以了解一下
(福利推荐:【腾讯云】服务器最新限时优惠活动,云服务器1核2G仅99元/年、2核4G仅768元/3年,立即抢购>>>:9i0i.cn/qcloud

(福利推荐:你还在原价购买阿里云服务器?现在阿里云0.8折限时抢购活动来啦!4核8G企业云服务器仅2998元/3年,立即抢购>>>:9i0i.cn/aliyun

前言

因为项目测试需要,我需要可以快速知道自己推流的多路视频流质量,于是我想到可以使用html网页来播放视频,实现效果极其简单,方法有好几种,以下是几种记录:

注意:测试过,VLC需要使用360急速浏览器,于是以下都是基于360急速浏览器测试的:

一、Demo1:iframe

video_url_player.html代码:

<html>
<head>
  <style>
    html,body,div{margin:1px;padding:0px;}
    td{padding:0px 1px 1px 0px;}
    table{border-collapse:collapse;border:0px solid #ff0000;text-align:center;}
  </style>
</head>
<body>
<table width=100% height=100%>
  <tr>
    <td><iframe frameborder=0 src=http://vfx.mtime.cn/Video/2021/11/16/mp4/211116131456748178.mp4 width=100% height=100%></iframe></td>
    <td><iframe frameborder=0 src=http://vfx.mtime.cn/Video/2021/11/16/mp4/211116131456748178.mp4 width=100% height=100%></iframe></td>
    <td><iframe frameborder=0 src=http://vfx.mtime.cn/Video/2021/11/16/mp4/211116131456748178.mp4 width=100% height=100%></iframe></td>
  </tr>
  <tr>
    <td><iframe frameborder=0 src=http://vfx.mtime.cn/Video/2021/11/16/mp4/211116131456748178.mp4 width=100% height=100%></iframe></td>
    <td><iframe frameborder=0 src=http://vfx.mtime.cn/Video/2021/11/16/mp4/211116131456748178.mp4 width=100% height=100%></iframe></td>
  </tr>
</table>
</body>
</html>

效果:

说明:

1. 支持几种常见的播放格式,无论是本地还是网络视频流都可以

2. 支持的格式不是特别多,一些特殊格式,无法播放

二、Demo2:VLC插件

需要安装VLC,然后就可以了,不过浏览器必须使用低版本的浏览器,测试一下很多浏览器不行,但是发现360急速浏览器就不需要所谓的低版本。

html代码:

<html>
<head>
</head>
<body> 
	<embed type="application/x-vlc-plugin" pluginspage="http://www.videolan.org"
		version="VideoLAN.VLCPlugin.2" width="320" height="240" id="vlc"
		target="file:///C:/Users/YJL/Desktop/testVideo/1080p_60fps_h264.mp4">
	</embed>
		<embed type="application/x-vlc-plugin" pluginspage="http://www.videolan.org"
		version="VideoLAN.VLCPlugin.2" width="320" height="240" id="vlc"
		target="file:///C:/Users/YJL/Desktop/testVideo/1080p_60fps_h264.mp4">
	</embed>
		<embed type="application/x-vlc-plugin" pluginspage="http://www.videolan.org"
		version="VideoLAN.VLCPlugin.2" width="320" height="240" id="vlc"
		target="file:///C:/Users/YJL/Desktop/testVideo/1080p_60fps_h264.mp4">
	</embed>
		<embed type="application/x-vlc-plugin" pluginspage="http://www.videolan.org"
		version="VideoLAN.VLCPlugin.2" width="320" height="240" id="vlc"
		target="file:///C:/Users/YJL/Desktop/testVideo/1080p_60fps_h264.mp4">
	</embed>
		<embed type="application/x-vlc-plugin" pluginspage="http://www.videolan.org"
		version="VideoLAN.VLCPlugin.2" width="320" height="240" id="vlc"
		target="file:///C:/Users/YJL/Desktop/testVideo/1080p_60fps_h264.mp4">
	</embed>
		<embed type="application/x-vlc-plugin" pluginspage="http://www.videolan.org"
		version="VideoLAN.VLCPlugin.2" width="320" height="240" id="vlc"
		target="file:///C:/Users/YJL/Desktop/testVideo/1080p_60fps_h264.mp4">
	</embed>
		<embed type="application/x-vlc-plugin" pluginspage="http://www.videolan.org"
		version="VideoLAN.VLCPlugin.2" width="320" height="240" id="vlc"
		target="file:///C:/Users/YJL/Desktop/testVideo/1080p_60fps_h264.mp4">
	</embed>
		<embed type="application/x-vlc-plugin" pluginspage="http://www.videolan.org"
		version="VideoLAN.VLCPlugin.2" width="320" height="240" id="vlc"
		target="file:///C:/Users/YJL/Desktop/testVideo/1080p_60fps_h264.mp4">
	</embed>
		<embed type="application/x-vlc-plugin" pluginspage="http://www.videolan.org"
		version="VideoLAN.VLCPlugin.2" width="320" height="240" id="vlc"
		target="file:///C:/Users/YJL/Desktop/testVideo/1080p_60fps_h264.mp4">
	</embed>
		<embed type="application/x-vlc-plugin" pluginspage="http://www.videolan.org"
		version="VideoLAN.VLCPlugin.2" width="320" height="240" id="vlc"
		target="file:///C:/Users/YJL/Desktop/testVideo/1080p_60fps_h264.mp4">
	</embed>
		<embed type="application/x-vlc-plugin" pluginspage="http://www.videolan.org"
		version="VideoLAN.VLCPlugin.2" width="320" height="240" id="vlc"
		target="file:///C:/Users/YJL/Desktop/testVideo/1080p_60fps_h264.mp4">
	</embed>
		<embed type="application/x-vlc-plugin" pluginspage="http://www.videolan.org"
		version="VideoLAN.VLCPlugin.2" width="320" height="240" id="vlc"
		target="file:///C:/Users/YJL/Desktop/testVideo/1080p_60fps_h264.mp4">
	</embed>
</body>
</html>

效果:

说明:

可以自由排布,以及支持非常多的格式,只要安装好环境以后,就可以使用,只是浏览器比较麻烦,但是效果和质量是真的好。

三、Demo3:使用一些常见的js

优势:嵌入简单,而且自动使用OpenGL渲染,有些支持硬件加速。

1. veoplayer

html代码:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>videoplayer</title>
    <script src="http://9i0i.com/pic.php?p=./veoplayer.global.min.js"></script>
	<style>
      /* 容器元素 */
      .container {
        display: grid;
        grid-template-columns: repeat(3, 1fr); /* 列数为3,每列平均分配剩余空间 */
        grid-template-rows: repeat(4, 1fr); /* 行数为4,每行平均分配剩余空间 */
        grid-gap: 10px; /* 单元格之间的间距 */
      }
      /* 单元格元素 */
      .cell {
        background-color: #ccc; /* 背景颜色 */
        padding: 20px; /* 内边距 */
        text-align: center; /* 文字居中 */
      }
    </style>
  </head>
  <body>
    <canvas id="video-canvas"></canvas>
	<script type="text/javascript">
      document.addEventListener('click', () => {
		let player = new JSMpeg.Player("rtsp://127.0.0.1:8554/live",{
			canvas: document.getElementById('jsmpeg-canvas'),
			// 要在用户点击过页面后,才可以播放声音
			// audio: false,
		})
	  }, { once: true })
    </script>
  <div class="container">
    <div class="cell" id="veo0"></div>
	<div class="cell" id="veo1"></div>
	<div class="cell" id="veo2"></div>
	<div class="cell" id="veo3"></div>
	<div class="cell" id="veo4"></div>
	<div class="cell" id="veo5"></div>
	<div class="cell" id="veo6"></div>
	<div class="cell" id="veo7"></div>
	<div class="cell" id="veo8"></div>
	<div class="cell" id="veo9"></div>
	<div class="cell" id="veo10"></div>
	<div class="cell" id="veo11"></div>
  </div>
    <script type="text/javascript">
      let player0 = new VeoPlayer({
        id: "veo0",
		autoplay: true,
        url: "./test.mp4",
        height: 660,
        width: 445,
        style: {
          themeColor: "#91CB40",
          processColor: "#91CB40",
          animation: true,
          processHeight: 8,
        },
      });
    </script>
	    <script type="text/javascript">
      let player1 = new VeoPlayer({
        id: "veo1",
        autoplay: true,
        url: "./test.mp4",
        height: 660,
        width: 445,
        style: {
          themeColor: "#91CB40",
          processColor: "#91CB40",
          animation: true,
          processHeight: 8,
        },
      });
    </script>
	    <script type="text/javascript">
      let player2 = new VeoPlayer({
        id: "veo2",
        autoplay: true,
        url: "./test.mp4",
        height: 660,
        width: 445,
        style: {
          themeColor: "#91CB40",
          processColor: "#91CB40",
          animation: true,
          processHeight: 8,
        },
      });
    </script>
	    <script type="text/javascript">
      let player3 = new VeoPlayer({
        id: "veo3",
        url: "./test.mp4",
        height: 660,
        width: 445,
        style: {
          themeColor: "#91CB40",
          processColor: "#91CB40",
          animation: true,
          processHeight: 8,
        },
      });
    </script>
	    <script type="text/javascript">
      let player4 = new VeoPlayer({
        id: "veo4",
        url: "./test.mp4",
        height: 660,
        width: 445,
        style: {
          themeColor: "#91CB40",
          processColor: "#91CB40",
          animation: true,
          processHeight: 8,
        },
      });
    </script>
	    <script type="text/javascript">
      let player5 = new VeoPlayer({
        id: "veo5",
        url: "./test.mp4",
        height: 660,
        width: 445,
        style: {
          themeColor: "#91CB40",
          processColor: "#91CB40",
          animation: true,
          processHeight: 8,
        },
      });
    </script>
	<script type="text/javascript">
      let player6 = new VeoPlayer({
        id: "veo6",
        url: "./test.mp4",
        height: 660,
        width: 445,
        style: {
          themeColor: "#91CB40",
          processColor: "#91CB40",
          animation: true,
          processHeight: 8,
        },
      });
    </script>
	<script type="text/javascript">
      let player7 = new VeoPlayer({
        id: "veo7",
        url: "./test.mp4",
        height: 660,
        width: 445,
        style: {
          themeColor: "#91CB40",
          processColor: "#91CB40",
          animation: true,
          processHeight: 8,
        },
      });
    </script>
	    <script type="text/javascript">
      let player8 = new VeoPlayer({
        id: "veo8",
        url: "./test.mp4",
        height: 660,
        width: 445,
        style: {
          themeColor: "#91CB40",
          processColor: "#91CB40",
          animation: true,
          processHeight: 8,
        },
      });
    </script>
	    <script type="text/javascript">
      let player9 = new VeoPlayer({
        id: "veo9",
        url: "./test.mp4",
        height: 660,
        width: 445,
        style: {
          themeColor: "#91CB40",
          processColor: "#91CB40",
          animation: true,
          processHeight: 8,
        },
      });
    </script>
	    <script type="text/javascript">
      let player10 = new VeoPlayer({
        id: "veo10",
        url: "./test.mp4",
        height: 660,
        width: 445,
        style: {
          themeColor: "#91CB40",
          processColor: "#91CB40",
          animation: true,
          processHeight: 8,
        },
      });
    </script>
	    <script type="text/javascript">
      let player11 = new VeoPlayer({
        id: "veo11",
        url: "./test.mp4",
        height: 660,
        width: 445,
        style: {
          themeColor: "#91CB40",
          processColor: "#91CB40",
          animation: true,
          processHeight: 8,
        },
      });
    </script>
  </body>
</html>

一样可以支持多种格式,效果还不错,不过支持的没有VLC的多。

相关文件看文章后面源码

2. kurento 播放rtsp

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="expires" content="0">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="shortcut icon" href="./img/kurento.png" type="image/png" />
<script src="http://9i0i.com/pic.php?p=./js/jquery.min.js"></script>
<script src="http://9i0i.com/pic.php?p=./js/kurento-client.min.js"></script>
<script src="http://9i0i.com/pic.php?p=./js/kurento-utils.min.js"></script>
<script src="http://9i0i.com/pic.php?p=./js/index.js"></script>
<title>Kurento RTSP to WebRTC player</title>
</head>
<body>
	<div class="container">
		<div class="page-header">
			<h1>Kurento RTSP to WebRTC player</h1>
		</div>
		<div class="row">
			<div class="col-md-5">
				<h3>播放窗口</h3>
				<video id="videoOutput" autoplay width="480px" height="360px" style="border: 1px solid #857f7f;" poster="./img/webrtc.png"></video>
				</br>
				rtsp/http地址: <input style="width:350px;" id="address" type="text">
				</br></br>
			</div>
			<div class="col-md-2">
				<a id="start" href="#" class="btn btn-success"><span
					class="glyphicon glyphicon-play"></span> 播放</a><br /> <br /> <a
					id="stop" href="#" class="btn btn-danger"><span
					class="glyphicon glyphicon-stop"></span> 暂停</a>
			</div>
		</div>
	</div>
</body>
</html>

这个是别人的代码,测试可用

3. video.js 

这个没测试成功

相关源码:

链接: https://pan.baidu.com/s/19p9qroD-xx5SxX4avW2CEw?pwd=v4cq 提取码: v4cq 

到此这篇关于html网页播放多个视频的几种方法的文章就介绍到这了,更多相关html播放多个视频内容请搜索程序员之家以前的文章或继续浏览下面的相关文章,希望大家以后多多支持程序员之家!

相关文章

  • Html5 video 标签 src 用数据流方式播放视频

    HTML5中的video标签用于播放视频文件的,本文介绍了Html5 video 标签 src 用数据流方式播放视频,具有一定的参考价值,感兴趣的可以了解一下
    2023-09-27
  • HTML中实现音乐或视频自动播放案例详解

    由于期末大作业我想插入一个背景音乐,实现点开网页就会自动播放音频的效果,今天通过本文给大家分享下我基于HTML实现音乐或视频自动播放功能,代码简单易懂,需要的朋友参
    2022-05-27
  • HTML5 video循环播放多个视频的方法步骤

    这篇文章主要介绍了HTML5 video循环播放多个视频的方法步骤,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来
    2020-08-06
  • html5中嵌入视频自动播放的问题解决

    这篇文章主要介绍了html5中嵌入视频自动播放的问题解决,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起
    2020-05-25
  • html5自动播放mov格式视频的实例代码

    这篇文章主要介绍了html5自动播放mov格式视频的实例代码,非常不错,具有一定的参考借鉴价值,需要的朋友可以参考下
    2020-01-14
  • HTML5自定义视频播放器源码

    这篇文章主要介绍了HTML5自定义视频播放器源码,非常不错,具有一定的参考借鉴价值,需要的朋友可以参考下
    2020-01-06
  • HTML5 播放 RTSP 视频的实例代码

    目前大多数网络摄像头都是通过 RTSP 协议传输视频流的,但是 HTML 并不标准支持 RTSP 流。本文重点给大家介绍HTML5 播放 RTSP 视频的实例代码,需要的朋友参考下吧
    2019-07-29
  • HTML5 视频播放(video),JavaScript控制视频的实例代码

    这篇文章主要介绍了HTML5 视频播放(video),JavaScript控制视频的实例代码,需要的朋友参考下吧
    2018-10-08
  • HTML5视频播放插件 video.js介绍

    这篇文章主要介绍了HTML5视频播放插件 video.js介绍 ,需要的朋友可以参考下
    2018-09-29
  • html5 视频播放解决方案

    这里主要研究的是通过应用html5来解决视频播放的问题。Adobe公司因为战略错误,忽视了移动互联这块,移动终端对flash支持并不好,特别是苹果终端都不支持flash(苹果电脑和
    2016-11-06

最新评论

?


http://www.vxiaotou.com