• js播放m3u8格式视频


    引入 hls 和 jquery

    代码片段

    <!DOCTYPE html>
    <html>
    	<head>
    		<meta charset="utf-8" />
    		<meta name="viewport" content="width=device-width, initial-scale=1">
    		<title>video</title>
    	</head>
    	<body>
    
    		<button type="button" class="btn btn-success" id="bt" onclick="bt()">播放</button>
    		<div style=" 50%; height: 50%;">
    			<video id="testVideo" src="" controls preload></video>
    		</div>
    		<!-- 引入jq -->
    		<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
    		<!-- 需要引入hls.js -->
    		<script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script>
    		<script>
    			$(function() {
    				$('#testVideo').hide();
    			});
    
    			function bt() {
    				loadVideo('https://v6.szjal.cn/20201212/ggJHXPox/index.m3u8');
    				$('#bt').hide();
    				$('#testVideo').show();
    			}
    
    			function loadVideo(vedio_url) {
    				var video = document.getElementById('testVideo');
    				if (Hls.isSupported()) {
    					var hls = new Hls();
    					hls.loadSource(vedio_url);
    					hls.attachMedia(video);
    					hls.on(Hls.Events.MANIFEST_PARSED, function() {
    						video.play();
    					});
    				} else if (video.canPlayType('application/vnd.apple.mpegurl')) {
    					video.src = vedio_url;
    					video.addEventListener('loadedmetadata', function() {
    						video.play();
    					});
    				}
    			}
    		</script>
    	</body>
    </html>
    
    
    有问题联系QQ1291481728或在下方评论,会在第一时刻处理。
  • 相关阅读:
    CODE[VS] 1018 单词接龙
    Linux提示BOOT空间不足问题
    CODE[VS] 1017 乘积最大
    关于printf输出结果的一些问题
    CODE[VS] 1220 数字三角形
    redux
    Promise面试题
    学习Promise笔记
    js 事件委托 事件代理
    前端通信、跨域
  • 原文地址:https://www.cnblogs.com/ooo51o/p/15540662.html
Copyright © 2020-2023  润新知