uniapp远程摄像头流界面上显示

用到的插件:dplayer、hls

dplayer官网:dplayer

dplayer官网npm安装的是最新版本(1.27.1),真机运行异常了,可以安装历史版本 dplayer历史版本

远程摄像头视频流格式:m3u8

可以用来测试的视频流(有的用不了,多试几个,找可以用的):m3u8测试视频

安装hls,任选其一
npm安装
下载hls文件

安装dplayer

使用 npm:

bash 复制代码
npm install dplayer --save

使用 Yarn:

bash 复制代码
yarn add dplayer

代码示例

javascript 复制代码
<template>
	<view class="containerLayout">
		<div id="dplayer"></div>
	</view>
</template>

<script>
//先加载hls插件、再加载dplayer插件;
import '/pages/utils/hls.js'
import Dplayer from 'dplayer'
	export default {
		data() {
			return {
				videoSrc: 'http://220.161.87.62:8800/hls/0/index.m3u8',
				dp: null,
			}
		},
		onLaunch() {
			console.log('onLaunch')
		},
		onReady() {
			
		},
		mounted() {
			//data里的远程摄像头地址
			const vs = this.videoSrc
			
			this.dp = new Dplayer({
				container: document.getElementById('dplayer'),
				autoplay: true, //是否自动播放
				loop: true,//视频是否循环播放
				lang: 'zh-cn',
				live: true,
				screenshot: false,//是否开启截图
				hotkey: true,//是否开启热键
				preload: 'auto',//视频是否预加载
				volume: 0.7,//默认音量
				mutex: true,//阻止多个播放器同时播放,当前播放器播放时暂停其他播放器
				video: {
					url: vs, //视频地址
					type: 'customHls',
					customType: {
						customHls: function(video, player) {
							const hls = new Hls()  //实例化Hls  解析m3u8
							hls.loadSource(video.src)
							hls.attachMedia(video)
						}
					},
				 },
			 });
			 this.dp.on('canplay', function() {
			 	console.log('视频正常播放')
			 });
			 this.dp.on('error', function() {
			 	console.log('视频播放异常')
			 });

			
		},
		onLoad() {
			
		},
		
		onShow() {
		},
		
		methods: {
			
			playvideo(vs){
			},
			//----------------------------
			
		}
		
	}
</script>
<style>
	.containerLayout{
		margin: 0;
		padding: 0;
		border: 0;
		width: 100vw;
		height: 100vh;
		display: flex;
		flex-direction: column;
		z-index: 100;
	}
</style>
相关推荐
叱咤少帅(少帅)2 天前
Uniapp开发pc端,小程序和APK
小程序·uni-app
2501_915918412 天前
iOS性能测试工具 Instruments、Keymob的使用方法 不局限 FPS
android·ios·小程序·https·uni-app·iphone·webview
2501_915918413 天前
iOS 混淆流程 提升 IPA 分析难度 实现 IPA 深度加固
android·ios·小程序·https·uni-app·iphone·webview
前端 贾公子3 天前
解决uni-app 输入框,键盘弹起时页面整体上移问题
前端·vue.js·uni-app
Muchen灬3 天前
【uniapp】(5) 创建gitee仓库并推送源码
gitee·uni-app
Muchen灬3 天前
【uniapp】(6) uniapp中使用vuex
uni-app
2501_915909063 天前
React Native 上架 App Store:项目运行与审核构建的流程
android·ios·小程序·https·uni-app·iphone·webview
李庆政3703 天前
uniapp+unicloud打包部署微信小程序
微信小程序·小程序·uni-app
2501_915909063 天前
苹果 Safari 浏览器抓包 页面刷新后的请求分析
android·前端·ios·小程序·uni-app·iphone·safari